mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 20:19:30 +00:00
Rewrite PasswordReset constructor to check for token in record
This commit is contained in:
@@ -11,21 +11,28 @@ class PasswordReset {
|
|||||||
nonce;
|
nonce;
|
||||||
expires;
|
expires;
|
||||||
|
|
||||||
constructor(userId) {
|
constructor(userId, token) {
|
||||||
const sql = `
|
const sql = `
|
||||||
select
|
select
|
||||||
|
userId,
|
||||||
token,
|
token,
|
||||||
nonce,
|
nonce,
|
||||||
expires,
|
UNIX_TIMESTAMP(expires) as expires
|
||||||
userId
|
|
||||||
from passwordReset
|
from passwordReset
|
||||||
where
|
where
|
||||||
userId = ?;
|
userId = ?
|
||||||
|
and token = ?;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
return (async () => {
|
return (async () => {
|
||||||
const conn = await new DatabaseConnectionPool();
|
const conn = await new DatabaseConnectionPool();
|
||||||
const record = await conn.runQuery(sql, [ userId ]);
|
const record = await conn.runQuery(sql, [
|
||||||
|
userId,
|
||||||
|
token
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!record.length)
|
||||||
|
throw new Error('No password reset found');
|
||||||
|
|
||||||
for (const [ k, v ] of Object.entries(record[0]))
|
for (const [ k, v ] of Object.entries(record[0]))
|
||||||
this[k] = v;
|
this[k] = v;
|
||||||
@@ -85,7 +92,7 @@ class PasswordReset {
|
|||||||
expires
|
expires
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return new PasswordReset(u.id);
|
return new PasswordReset(u.id, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user