feat: Adding check-account endpoint
This commit is contained in:
@@ -5,6 +5,8 @@ const services= require('./services.js');
|
||||
router.post('/authorize', services.AuthorizeJWT);
|
||||
router.get('/authorize/:session_token', services.RenewJWT);
|
||||
|
||||
router.get('/check-account/:email', services.checkAccount );
|
||||
|
||||
router.post('/signup', services.TryCreateAccount);
|
||||
router.patch('/signup', services.ConfirmAccount);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ const { API_CONFIG, ROOT_PATH, LIB_PATH, HANDLERS_PATH } = process.env;
|
||||
const apiConfig = require( `${ROOT_PATH}/${API_CONFIG}` );
|
||||
const { genKey, toSha256 } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
|
||||
const { emailEvent , EMAIL_EVENTS } = require( `${ROOT_PATH}/${HANDLERS_PATH}/MailClient` );
|
||||
const { create_account, already_exists, login, login_with_session_token, reset_password } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Account` );
|
||||
const { create_account, already_exists, verify_driver_account, login, login_with_session_token, reset_password } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Account` );
|
||||
const { Validator } = require( "jsonschema" );
|
||||
|
||||
const jwtSecret = apiConfig.authentication.jwtSecret;
|
||||
@@ -259,4 +259,15 @@ const ConfirmRecoverPwd = async(req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { AuthorizeJWT, RenewJWT, TryCreateAccount, ConfirmAccount, RecoverPwd, ConfirmRecoverPwd};
|
||||
const checkAccount = async(req, res) => {
|
||||
try{
|
||||
const email = req.params.email;
|
||||
const driver_account_val = await verify_driver_account( email );
|
||||
return res.status(200).send( driver_account_val );
|
||||
} catch ( err ){
|
||||
console.error( err );
|
||||
return res.status(500).send({ error : "AuthManagement: Internal error" });
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { AuthorizeJWT, RenewJWT, TryCreateAccount, ConfirmAccount, RecoverPwd, ConfirmRecoverPwd, checkAccount};
|
||||
|
||||
@@ -33,6 +33,27 @@ async function already_exists( email ){
|
||||
}
|
||||
}
|
||||
|
||||
async function verify_driver_account( email ){
|
||||
const user = await UserModel.findOne( { email } );
|
||||
const retVal = {
|
||||
has_account:false,
|
||||
isVerified:false,
|
||||
has_password:false
|
||||
};
|
||||
|
||||
if( !user ){
|
||||
retVal.has_account = false;
|
||||
retVal.isVerified = false;
|
||||
retVal.has_password = false;
|
||||
}else{
|
||||
retVal.has_account = true;
|
||||
retVal.isVerified = user.isVerified;
|
||||
retVal.has_password = ( !user.password )? false : true;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
async function login( email , password ){
|
||||
let safe_password = toSha256( password + pwd_secret );
|
||||
const user = await UserModel.findOne({
|
||||
@@ -49,4 +70,4 @@ async function login_with_session_token( session_token ){
|
||||
return user;
|
||||
}
|
||||
|
||||
module.exports = { create_account, already_exists, login, login_with_session_token, reset_password };
|
||||
module.exports = { create_account, already_exists, verify_driver_account, login, login_with_session_token, reset_password };
|
||||
|
||||
Reference in New Issue
Block a user