({ }, mail: string)
| 252 | |
| 253 | @post('mail', Types.Email) |
| 254 | async post({ }, mail: string) { |
| 255 | if (await user.getByEmail('system', mail)) throw new UserAlreadyExistError(mail); |
| 256 | const mailDomain = mail.split('@')[1]; |
| 257 | if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain); |
| 258 | await Promise.all([ |
| 259 | this.limitRate('send_mail', 60, 1, mail), |
| 260 | this.limitRate('send_mail', 3600, 30), |
| 261 | oplog.log(this, 'user.register', {}), |
| 262 | ]); |
| 263 | const t = await token.add( |
| 264 | token.TYPE_REGISTRATION, |
| 265 | system.get('session.unsaved_expire_seconds'), |
| 266 | { |
| 267 | mail, |
| 268 | redirect: this.domain.registerRedirect, |
| 269 | identity: { |
| 270 | provider: 'mail', |
| 271 | platform: 'mail', |
| 272 | id: mail, |
| 273 | }, |
| 274 | }, |
| 275 | ); |
| 276 | const prefix = this.domain.host |
| 277 | ? `${this.domain.host instanceof Array ? this.domain.host[0] : this.domain.host}` |
| 278 | : system.get('server.url'); |
| 279 | if (system.get('smtp.verify') && system.get('smtp.user')) { |
| 280 | const m = await this.renderHTML('user_register_mail.html', { |
| 281 | path: `/register/${t[0]}`, |
| 282 | url_prefix: prefix.endsWith('/') ? prefix.slice(0, -1) : prefix, |
| 283 | }); |
| 284 | await sendMail(mail, 'Sign Up', 'user_register_mail', m.toString()); |
| 285 | this.response.template = 'user_register_mail_sent.html'; |
| 286 | this.response.body = { mail }; |
| 287 | } else this.response.redirect = this.url('user_register_with_code', { code: t[0] }); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | class UserRegisterWithCodeHandler extends Handler { |
nothing calls this directly
no test coverage detected