mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 20:19:30 +00:00
Implemented PasswordReset generatePasswordReset
This commit is contained in:
@@ -50,8 +50,42 @@ class PasswordReset {
|
||||
return [ nonce, token ];
|
||||
}
|
||||
|
||||
static generatePasswordReset() {
|
||||
static async generatePasswordReset(userId) {
|
||||
const u = await new (require('./User'))(null, userId);
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
|
||||
let sql = `
|
||||
delete from passwordReset
|
||||
where userId = ?;
|
||||
`;
|
||||
|
||||
await conn.runQuery(sql, [ u.id ]);
|
||||
|
||||
const [ nonce, token ] = await PasswordReset.hashToken(u);
|
||||
|
||||
const d = new Date();
|
||||
d.setHours(d.getHours() + 1);
|
||||
const expires = d.getTime() / 1000;
|
||||
|
||||
sql = `
|
||||
insert into passwordReset
|
||||
(
|
||||
userId,
|
||||
token,
|
||||
nonce,
|
||||
expires
|
||||
)
|
||||
values (?, ?, ?, FROM_UNIXTIME(?));
|
||||
`;
|
||||
|
||||
await conn.runQuery(sql, [
|
||||
u.id,
|
||||
token,
|
||||
nonce,
|
||||
expires
|
||||
]);
|
||||
|
||||
return new PasswordReset(u.id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user