(domainId: string, current: string, email: string)
| 228 | @param('password', Types.Password) |
| 229 | @param('mail', Types.Email) |
| 230 | async postChangeMail(domainId: string, current: string, email: string) { |
| 231 | const mailDomain = email.split('@')[1]; |
| 232 | if (await BlackListModel.get(`mail::${mailDomain}`)) throw new BlacklistedError(mailDomain); |
| 233 | if (this.session.sudoUid) { |
| 234 | const udoc = await user.getById(domainId, this.session.sudoUid); |
| 235 | if (!udoc) throw new UserNotFoundError(this.session.sudoUid); |
| 236 | await udoc.checkPassword(current); |
| 237 | } else await this.user.checkPassword(current); |
| 238 | const udoc = await user.getByEmail(domainId, email); |
| 239 | if (udoc) throw new UserAlreadyExistError(email); |
| 240 | await this.limitRate('send_mail', 3600, 30); |
| 241 | const [code] = await token.add( |
| 242 | token.TYPE_CHANGEMAIL, |
| 243 | system.get('session.unsaved_expire_seconds'), |
| 244 | { uid: this.user._id, email }, |
| 245 | ); |
| 246 | const prefix = (this.domain.host || [])[0] || system.get('server.url'); |
| 247 | const m = await this.renderHTML('user_changemail_mail.html', { |
| 248 | path: `/home/changeMail/${code}`, |
| 249 | uname: this.user.uname, |
| 250 | url_prefix: prefix.endsWith('/') ? prefix.slice(0, -1) : prefix, |
| 251 | }); |
| 252 | await mail.sendMail(email, 'Change Email', 'user_changemail_mail', m.toString()); |
| 253 | this.response.template = 'user_changemail_mail_sent.html'; |
| 254 | } |
| 255 | |
| 256 | @param('platform', Types.String) |
| 257 | async postLinkAccount({ }, platform: string) { |
nothing calls this directly
no test coverage detected