Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- reset.ejs
- <html>
- <body style="margin-left:0px;">
- <div class="custom-header">
- <div class="custom-header-left">
- </div>
- <div class="custom-header-button">
- </div>
- <div class="custom-header-right">
- <a class="navbar-brand">
- <img alt="AGD" src="agdlogo.png" style="width:70%; margin-top:-22%;">
- </a>
- <a class="navbar-brand" href="/"> XXX </a>
- <a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </a>
- </div>
- </div>
- <!-- Top Bar-->
- <div id="fullpage">
- <div class="">
- <div class="col-md-12 custom-margin-top">
- <div class="panel panel-primary text-left">
- <div class="panel-heading">Reset your Password</div>
- <div class="panel-body">
- <div class="col-md-10 ">
- <form id="resetpass" role="form" class="form">
- <div>
- <div class="form-group">
- <label for="InputEmail">New Password</label>
- <input type="password" class="form-control" id="password" class="password" name="password" placeholder="Enter Email" required>
- <label for="InputEmail">Confirm Password</label>
- <input type="password" class="form-control" id="repass" class="repass" name="repass" placeholder="Enter Email" required>
- <!-- <input type="hidden" name="token" id="token">-->
- <button type="submit">Submit</button>
- </div>
- </form>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </body>
- <script>
- var params = location.href;
- var paramsplit = params.split('/');
- //console.log(paramsplit);
- $("#resetpass").submit(function (e) {
- var resetData = {
- password: $("#password").val(),
- repass: $("#repass").val(),
- token: paramsplit[4]
- }
- console.log(resetData);
- // console.log(resetData);
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: '/reset/:token',
- data: JSON.stringify(resetData),
- success: function (data) {
- //console.log(data); // show response from the php script.
- }
- });
- // e.preventDefault(); // avoid to execute the actual submit of the form.
- });
- </script>
- <style CSS>
- @import url("https://bootswatch.com/flatly/bootstrap.min.css");
- </style>
- </html>
- exports.resetpassword = function (req, res) {
- var data = req.body;
- async.waterfall([
- function (done) {
- User.findOne({
- resetPasswordToken: req.body.token,
- resetPasswordExpires: {
- $gt: Date.now()
- }
- }, function (err, user) {
- if (!user) {
- res.render('tinypage/regnotify', {
- title: "Something is wrong",
- alerttype: "alert-danger",
- message: "Something wrong with your password change."
- });
- } else {
- user.password = req.body.password;
- user.resetPasswordToken = '';
- user.resetPasswordExpires = '';
- user.save(function (err, user) {
- done(err, user);
- });
- }
- });
- },
- function (user, done) {
- var smtpTransport = nodemailer.createTransport('SMTP', {
- service: 'Mailgun',
- auth: {
- user: 'sdfa',
- pass: 'afdafsa'
- }
- });
- var mailOptions = {
- to: user.email,
- from: 'agdtrack@s.com',
- subject: 'Your password has been changed',
- text: 'Hello,nn' +
- 'This is a confirmation that the password for your account ' + req.body.token + ' has just been changed.n'
- };
- smtpTransport.sendMail(mailOptions, function (err) {
- if (err) {
- res.render('tinypage/regnotify', {
- title: "Wrong",
- alerttype: "alert-danger",
- message: "Something wrong"
- });
- } else {
- return res.render('tinypage/regnotify', {
- title: "Success",
- alerttype: "alert-success",
- message: "Success! Your password has been changed."
- });
- done(err);
- }
- });
- }
- ],
- function (err) {
- res.redirect('/');
- });
- };
- exports.renderresetpage = function (req, res) {
- res.render('reset');
- };
- app.route('/reset/:token').get(mail.renderresetpage);
- app.route('/reset/:token').post(mail.resetpassword);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement