function encrypt(text){
  var algorithm = 'AES-256-CBC';
  var password = 'd6F3Efeq';
  var cipher = crypto.createCipher(algorithm,password)
  var crypted = cipher.update(text,'utf8','hex')
  crypted += cipher.final('hex');
  return crypted;
}

function dcrypt(encryptGenPwd)
{
  var algorithm = 'AES-256-CBC';
  var password = 'd6F3Efeq';
  var decipher = crypto.createDecipher(algorithm,password)
  var dec = decipher.update(encryptGenPwd,'hex','utf8')
  dec += decipher.final('utf8');
  return dec;
}

exports.forgotpassword = function(req,res){
  var newUser = new User(req.body);
  var forgotemail = req.body.forgotemail;
    var err="";
  async.waterfall([
    function (done){

      var token = encrypt(forgotemail);

      if (token=="" || !token)
      {
         crypto.randomBytes(20,function(err,buf){
        var token = buf.toString('hex');
       done(err,token);
      });
      }else{
      done(err,token);
      }
     },
   function (token,done){
      User.findOne({email:forgotemail},function(err,user){

        if (!user){
          res.json({success:false,message:'Email ID not Exists'});
        }
        else{
      User.update({email:forgotemail},{$set: {resetPasswordToken:
token,resetPasswordExpires:Date.now()}},function(err,user){
          if(err){
            res.json({success:true,message:'Error While updating Data'});
          }
          else if(!user){
           res.json({success:true,message:'Oops something went wrong please
try again later'});
          }
          else{
            done(err, token, user);
          }
        });
        }
      });
    },

  function(token,user, done){
    var smtpTransport = nodemailer.createTransport("SMTP",{
                        service: "Gmail",
                        auth: {
                            user: "@gmail.com",
                            pass: "  "
                        }
                    });
    var mailOptions = {

                    from: " <[email protected]>",
                        to: "Receiver Name <" + req.body.forgotemail + ">",
                           subject: "Forgot your password",
                             text: "",
                                html: "<p>we've received  your request to
reset the password for this email address.</p>"
                                  + " To reset your password please click
on this link or cut and paste this URL into your browser.<br>" +
                                    'http://' + req.headers.host +
'/resetpassword?token=' + token + '\n\n'
                                      }

        smtpTransport.sendMail(mailOptions,function(err){
        res.json({success : true, message : "An Email Has been sent to th
provided Email Address"});
        done(err,'done');
      });
    }
    ]);

}


On Mon, Jul 13, 2015 at 7:46 AM, sam <[email protected]> wrote:

>
> ```
> /* somewhere deep inside a module... */
> var token = Tokens.create();
> pair(email, token);
> send(email, token);
> ```
>
> ```
> /* in another module */
> Tokens.create = function() {
>   crypto.randomBytes(48, function(ex, buf) {
>     var token = buf.toString('hex');
>     return token;
>   })
> }
> ```
>
> Will the `Tokens.create()` be ran in parallel to `pair(email, token)` and
> `send(token, email)`? I'm trying to understand if i need to use a callback
> or not here
>
> Someone in IRC responded:
> "just google for callbacks, in a nutshell when the second argument of
> function is a function"
>
> Tokens.create doesn't take a callback, but the function it calls,
> `crypto.randomBytes`, does. So will `token = Tokens.create` be ran
> asynchronously?
>
>  --
> Job board: http://jobs.nodejs.org/
> New group rules:
> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
> Old group rules:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/dfcad4b1-b068-4743-8915-1c70f1b54efa%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/dfcad4b1-b068-4743-8915-1c70f1b54efa%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Best Regards
Shailendra Sen
LinkITes Infotech Pvt Ltd

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CAMD6rkoX0iU-wc8Z7eQAwLZ4QNt541YDZms8aSB%3DTpS7%3Dw9N2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to