mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
reset password API complete
This commit is contained in:
@ -139,7 +139,7 @@ async function remove(personId) {
|
||||
|
||||
async function confirmActivation(personId) {
|
||||
await knex.transaction(async (tr) => {
|
||||
await knex('Person')
|
||||
await tr('Person')
|
||||
.where('id', personId)
|
||||
.update({
|
||||
enabled: true
|
||||
@ -149,7 +149,6 @@ async function confirmActivation(personId) {
|
||||
.where('person_id', personId)
|
||||
.del();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Exporting a function
|
||||
|
@ -13,14 +13,47 @@
|
||||
|
||||
const knex = require('../utils/knex_config');
|
||||
|
||||
async function add(email, secret){
|
||||
async function add(email, secret) {
|
||||
await knex('RequestResetPassword')
|
||||
.insert({
|
||||
email,
|
||||
.insert({
|
||||
email,
|
||||
secret
|
||||
});
|
||||
}
|
||||
|
||||
async function findBySecret(secret) {
|
||||
return await knex('RequestResetPassword').where({
|
||||
secret
|
||||
}).first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a secret and a new password, update the Peron's personal password
|
||||
*
|
||||
* @param {*} password The new (hashed) password
|
||||
* @param {*} secret The secret received via e-mail (table RequestResetPassword)
|
||||
* @returns
|
||||
*/
|
||||
async function resetPassword(password, secret) {
|
||||
const request = await findBySecret(secret);
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
await knex.transaction(async tr => {
|
||||
await tr('Person').where({
|
||||
email: request.email
|
||||
}).update({
|
||||
password
|
||||
});
|
||||
|
||||
await tr('RequestResetPassword').where({
|
||||
email
|
||||
}).del();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add
|
||||
add,
|
||||
findBySecret,
|
||||
resetPassword
|
||||
}
|
Reference in New Issue
Block a user