mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 21:34:24 +00:00
pw reset done
This commit is contained in:
@@ -15,6 +15,15 @@
|
||||
// import and init
|
||||
const bcrypt = require( 'bcrypt' );
|
||||
const db = require( '../db/db.js' );
|
||||
const mm = require( '../mail/mailSender.js' );
|
||||
const mailManager = new mm();
|
||||
const fs = require( 'fs' );
|
||||
const path = require( 'path' );
|
||||
const token = require( '../token.js' );
|
||||
let createSSRApp = require( 'vue' ).createSSRApp;
|
||||
let renderToString = require( 'vue/server-renderer' ).renderToString;
|
||||
|
||||
const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/settings.config.json' ) ) );
|
||||
|
||||
module.exports.checkpassword = function checkpassword ( email, password ) {
|
||||
return new Promise( resolve => {
|
||||
@@ -38,4 +47,33 @@ module.exports.hashPassword = ( password ) => {
|
||||
return new Promise( resolve => {
|
||||
resolve( bcrypt.hashSync( password, 10 ) );
|
||||
} );
|
||||
};
|
||||
|
||||
module.exports.resetPassword = ( email ) => {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
db.checkDataAvailability( 'users', 'email', email ).then( dat => {
|
||||
if ( dat ) {
|
||||
const newPW = token.generateToken( 20 );
|
||||
this.hashPassword( newPW ).then( hash => {
|
||||
( async () => {
|
||||
db.writeDataSimple( 'users', 'email', email, { 'pass': hash } );
|
||||
const app = createSSRApp( {
|
||||
data() {
|
||||
return {
|
||||
password: newPW,
|
||||
host: settings.yourDomain
|
||||
};
|
||||
},
|
||||
template: '' + fs.readFileSync( path.join( __dirname + '/../../ui/en/signup/pwReset.html' ) )
|
||||
} );
|
||||
|
||||
mailManager.sendMail( email, await renderToString( app ), 'Password reset', settings.mailSender );
|
||||
resolve( 'ok' );
|
||||
} )();
|
||||
} );
|
||||
} else {
|
||||
reject( { 'code': 404, 'message': 'ERR_USER_NOT_FOUND' } );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
};
|
||||
Reference in New Issue
Block a user