UNPKG

@waline/vercel

Version:

vercel server for waline comment system

34 lines (25 loc) 828 B
const BaseRest = require('./rest.js'); module.exports = class extends BaseRest { constructor(...args) { super(...args); this.modelInstance = this.getModel('Users'); } async getAction() { const { token, email } = this.get(); const users = await this.modelInstance.select({ email }); if (think.isEmpty(users)) { return this.fail(this.locale('USER_NOT_EXIST')); } const user = users[0]; const match = user.type.match(/^verify:(\d{4}):(\d+)$/i); if (!match) { return this.fail(this.locale('USER_REGISTERED')); } if (token === match[1] && Date.now() < Number.parseInt(match[2])) { await this.modelInstance.update({ type: 'guest' }, { email }); this.redirect('/ui/login'); return; } return this.fail(this.locale('TOKEN_EXPIRED')); } };