//@route GET api/users/email/:emailaddress //@desc Validates the email address router.get('/email/:emailaddress',(req, res)=>{ var emailaddress = req.params.emailaddress; var regex = /^[a-zA-Z0-9\.\-\_\%\!\#\&\'\+\-\/\=\?\^\`\{\|\}\~\;]+@(?:[a-zA-Z0-9]+\.)+[A-Za-z]+$/ if (regex.test(emailaddress)) { res.json({'status':HttpStatus.OK, 'message':'Valid Email Address!'}); } else { res.status(HttpStatus.BAD_REQUEST).json('Invalid Email Address: ' + err); } });
/** * * @param request * @param reply */ const updateOne = async (request, reply) => { try { const result = await studentService.updateOne(request.params, request.query); reply.code(result.nModified ? HttpStatus.OK : HttpStatus.BAD_REQUEST).send(result.nModified === 1 ? { status: "ok" } : {}); } catch (e) { request.log.error(e); return Boom.boomify(e); } }
//@desc //@error send unauthorized status (401) function auth(req, res, next) { const token = req.header('x-auth-token'); if (!token) return res.status(HttpStatus.UNAUTHORIZED).json({msg: 'No Token, authorization denied!'}); try { // verify token const decoded = jwt.verify(token, config.get('jwtSecret')); // Add user from payload req.user = decoded; next(); } catch (e) { console.log('Token Exception: ' + e); res.status(HttpStatus.BAD_REQUEST).json({msg: `Authorization Token Isn\'t Valid, Authorization Failed! ${e}`}) } }
/** * * @param request * @param reply */ const findOne = async (request, reply) => { try { const requestParams = { ...request.body, ...request.query, ...request.params }; const document = await studentService.findOne(requestParams); reply.code(document ? HttpStatus.OK : HttpStatus.BAD_REQUEST).send(document || {}); } catch (e) { request.log.error(e); return Boom.boomify(e); } }
logger.logFullError(err, req.signature || `${req.method} ${req.url}`) const errorResponse = {} const status = err.isJoi ? HttpStatus.BAD_REQUEST : (err.httpStatus || _.get(err, 'response.status') || HttpStatus.INTERNAL_SERVER_ERROR)
//@desc Tests the password for strength making sure is has 8 charactes and // contain 1 lowercase, 1 uppercase, 1 numerid and 1 special character (e.g.,$&#@!^*&) // Strong: The password must be at least 8 charactes and contain 1 lowercase, 1 uppercase, 1 numerid and 1 special character (e.g.,$&#@!^*&) // Medium Strength is commented out for now. // Medium Strength: medium strength if it contains six characters or more and has at least one // lowercase and one uppercase alphabetical character or has at least one lowercase and one // numeric character or has at least one uppercase and one numeric character. // router.get('/pwdstrength/:password',(req, res) => { const password = decodeURI(req.params.password); let weak_password_note = 'The password must be at least 8 charactes and contain 1 lowercase, 1 uppercase, 1 numerid and 1 special character (e.g.,$&#@!^*&)'; var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})"); if (strongRegex.test(password)) { res.send(JSON.stringify({status: HttpStatus.OK, message: "Strong Password"})) } else { res.status(HttpStatus.BAD_REQUEST).json({'message':`${weak_password_note}`}); /* var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"); if (mediumRegex.test(password)) { res.send(JSON.stringify({status: true, message: "Medium Password (consider strengthening)"})) } else { res.status(HttpStatus.BAD_REQUEST).json({'message':`${weak_password_note}`}); } */ } });
HttpStatus.BAD_REQUEST, 'No token specified' );
HttpStatus.BAD_REQUEST, res.error.message );
return res.status(HttpStatus.BAD_REQUEST).json({msg: 'please enter all fields!'}) if (user) return res.status(HttpStatus.BAD_REQUEST).json({msg: 'User Already Exists'}); bcrypt.hash(password, salt, (err, hash) => { if (err) { res.status(HttpStatus.BAD_REQUEST).json('Hash Error ' + err); .catch(err => res.status(HttpStatus.BAD_REQUEST).json('Error: ' + err)); }); });
HttpStatus.BAD_REQUEST, res.error.message);
return res.status(HttpStatus.BAD_REQUEST).json({msg: 'Please provide an email address and a password.'}); if (!user) return res.status(HttpStatus.BAD_REQUEST).json({msg: 'User Doesn\'t Exist'});
//@route GET api/users/email/:emailaddress //@desc Validates the email address router.get('/email/:emailaddress',(req, res)=>{ var emailaddress = req.params.emailaddress; var regex = /^[a-zA-Z0-9\.\-\_\%\!\#\&\'\+\-\/\=\?\^\`\{\|\}\~\;]+@(?:[a-zA-Z0-9]+\.)+[A-Za-z]+$/ if (regex.test(emailaddress)) { res.json({'status':HttpStatus.OK, 'message':'Valid Email Address!'}); } else { res.status(HttpStatus.BAD_REQUEST).json('Invalid Email Address: ' + err); } });
//@desc Tests the password for strength making sure is has 8 charactes and // contain 1 lowercase, 1 uppercase, 1 numerid and 1 special character (e.g.,$&#@!^*&) // Strong: The password must be at least 8 charactes and contain 1 lowercase, 1 uppercase, 1 numerid and 1 special character (e.g.,$&#@!^*&) // Medium Strength is commented out for now. // Medium Strength: medium strength if it contains six characters or more and has at least one // lowercase and one uppercase alphabetical character or has at least one lowercase and one // numeric character or has at least one uppercase and one numeric character. // router.get('/pwdstrength/:password',(req, res) => { const password = decodeURI(req.params.password); let weak_password_note = 'The password must be at least 8 charactes and contain 1 lowercase, 1 uppercase, 1 numerid and 1 special character (e.g.,$&#@!^*&)'; var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})"); if (strongRegex.test(password)) { res.send(JSON.stringify({status: HttpStatus.OK, message: "Strong Password"})) } else { res.status(HttpStatus.BAD_REQUEST).json({'message':`${weak_password_note}`}); /* var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"); if (mediumRegex.test(password)) { res.send(JSON.stringify({status: true, message: "Medium Password (consider strengthening)"})) } else { res.status(HttpStatus.BAD_REQUEST).json({'message':`${weak_password_note}`}); } */ } });
return res.status(HttpStatus.BAD_REQUEST).json({msg: 'Please provide an email address and a password.'}); if (!user) return res.status(HttpStatus.BAD_REQUEST).json({msg: 'User Doesn\'t Exist'});
return res.status(HttpStatus.BAD_REQUEST).json({msg: 'please enter all fields!'}) if (user) return res.status(HttpStatus.BAD_REQUEST).json({msg: 'User Already Exists'}); bcrypt.hash(password, salt, (err, hash) => { if (err) { res.status(HttpStatus.BAD_REQUEST).json('Hash Error ' + err); .catch(err => res.status(HttpStatus.BAD_REQUEST).json('Error: ' + err)); }); });