Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- methods.signup = async (req,res,next) => {
- const errors = validationResult(req);
- if (!errors.isEmpty()) {
- return res.status(config.errorCodes.validation).json({errors:errors.array()});
- }
- let payload = req.body;
- var newUser = new User({
- username:payload.username,
- fullname:payload.fullname,
- email: payload.email,
- password: payload.password,
- urltoken:{
- token:null
- },
- actStatus: 0,
- provider: 'email',
- role:1
- });
- let hash = commonMethods.generatePasswordHash(payload.password);
- let token = commonMethods.createRandomString();
- let [a,b] = await Promise.all([hash,token]).catch(err=>{
- res.status(400).json({status:false,msg:"error in promise"})
- });
- newUser.password = a;
- newUser.urltoken.token = b;
- newUser.save(function(err){
- if(err) {
- return res.status(config.errorCodes.success).json({ status:false
- ,msg:"Error in saving userdata. Please try again",err});
- }
- else {
- commonMethods.sendMail(newUser);
- return res.status(config.errorCodes.success).json({"status":true,
- "msg":"Registered succesfully. Please Check your Email to verify
- your account.",newUser})
- }
- });
- }
- commonMethods.createRandomString = function(password){
- return new Promise(function(resolve, reject) {
- var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
- var string_length = 25;
- var randomstring = '';
- for (var i=0; i<string_length; i++) {
- var rnum = Math.floor(Math.random() * chars.length);
- randomstring += chars.substring(rnum,rnum+1);
- }
- reject(randomstring);
- // resolve(randomstring);
- })
- }
- UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
- (node:15172) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Add Comment
Please, Sign In to add comment