Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. reset.ejs
  2.  
  3. <html>
  4.  
  5.  
  6.  
  7. <body style="margin-left:0px;">
  8.  
  9. <div class="custom-header">
  10. <div class="custom-header-left">
  11.  
  12. </div>
  13.  
  14. <div class="custom-header-button">
  15.  
  16. </div>
  17.  
  18. <div class="custom-header-right">
  19. <a class="navbar-brand">
  20. <img alt="AGD" src="agdlogo.png" style="width:70%; margin-top:-22%;">
  21. </a>
  22. <a class="navbar-brand" href="/"> XXX &nbsp;</a>
  23. <a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  24. <span class="icon-bar"></span>
  25. <span class="icon-bar"></span>
  26. <span class="icon-bar"></span>
  27. </a>
  28. </div>
  29. </div>
  30.  
  31. <!-- Top Bar-->
  32.  
  33. <div id="fullpage">
  34. <div class="">
  35. <div class="col-md-12 custom-margin-top">
  36. <div class="panel panel-primary text-left">
  37. <div class="panel-heading">Reset your Password</div>
  38. <div class="panel-body">
  39.  
  40. <div class="col-md-10 ">
  41. <form id="resetpass" role="form" class="form">
  42. <div>
  43.  
  44. <div class="form-group">
  45.  
  46. <label for="InputEmail">New Password</label>
  47. <input type="password" class="form-control" id="password" class="password" name="password" placeholder="Enter Email" required>
  48. <label for="InputEmail">Confirm Password</label>
  49. <input type="password" class="form-control" id="repass" class="repass" name="repass" placeholder="Enter Email" required>
  50. <!-- <input type="hidden" name="token" id="token">-->
  51. <button type="submit">Submit</button>
  52. </div>
  53.  
  54. </form>
  55. </div>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60.  
  61.  
  62. </div>
  63.  
  64.  
  65.  
  66. </body>
  67.  
  68.  
  69. <script>
  70. var params = location.href;
  71. var paramsplit = params.split('/');
  72. //console.log(paramsplit);
  73. $("#resetpass").submit(function (e) {
  74.  
  75.  
  76. var resetData = {
  77. password: $("#password").val(),
  78. repass: $("#repass").val(),
  79. token: paramsplit[4]
  80. }
  81. console.log(resetData);
  82. // console.log(resetData);
  83. $.ajax({
  84. type: "POST",
  85. contentType: "application/json; charset=utf-8",
  86. url: '/reset/:token',
  87. data: JSON.stringify(resetData),
  88. success: function (data) {
  89. //console.log(data); // show response from the php script.
  90. }
  91. });
  92.  
  93. // e.preventDefault(); // avoid to execute the actual submit of the form.
  94. });
  95. </script>
  96. <style CSS>
  97. @import url("https://bootswatch.com/flatly/bootstrap.min.css");
  98. </style>
  99. </html>
  100.  
  101. exports.resetpassword = function (req, res) {
  102.  
  103.  
  104. var data = req.body;
  105.  
  106.  
  107.  
  108. async.waterfall([
  109. function (done) {
  110. User.findOne({
  111. resetPasswordToken: req.body.token,
  112. resetPasswordExpires: {
  113. $gt: Date.now()
  114. }
  115. }, function (err, user) {
  116.  
  117. if (!user) {
  118.  
  119. res.render('tinypage/regnotify', {
  120. title: "Something is wrong",
  121. alerttype: "alert-danger",
  122. message: "Something wrong with your password change."
  123.  
  124. });
  125.  
  126. } else {
  127.  
  128. user.password = req.body.password;
  129. user.resetPasswordToken = '';
  130. user.resetPasswordExpires = '';
  131. user.save(function (err, user) {
  132.  
  133. done(err, user);
  134.  
  135.  
  136.  
  137.  
  138. });
  139.  
  140.  
  141. }
  142.  
  143.  
  144. });
  145. },
  146. function (user, done) {
  147.  
  148. var smtpTransport = nodemailer.createTransport('SMTP', {
  149. service: 'Mailgun',
  150. auth: {
  151. user: 'sdfa',
  152. pass: 'afdafsa'
  153. }
  154. });
  155. var mailOptions = {
  156. to: user.email,
  157. from: 'agdtrack@s.com',
  158. subject: 'Your password has been changed',
  159. text: 'Hello,nn' +
  160. 'This is a confirmation that the password for your account ' + req.body.token + ' has just been changed.n'
  161. };
  162.  
  163.  
  164.  
  165.  
  166.  
  167. smtpTransport.sendMail(mailOptions, function (err) {
  168. if (err) {
  169. res.render('tinypage/regnotify', {
  170. title: "Wrong",
  171. alerttype: "alert-danger",
  172. message: "Something wrong"
  173.  
  174.  
  175.  
  176. });
  177.  
  178. } else {
  179. return res.render('tinypage/regnotify', {
  180. title: "Success",
  181. alerttype: "alert-success",
  182. message: "Success! Your password has been changed."
  183.  
  184.  
  185.  
  186. });
  187.  
  188. done(err);
  189.  
  190. }
  191.  
  192.  
  193.  
  194. });
  195.  
  196.  
  197. }
  198. ],
  199. function (err) {
  200.  
  201. res.redirect('/');
  202. });
  203. };
  204.  
  205. exports.renderresetpage = function (req, res) {
  206. res.render('reset');
  207. };
  208.  
  209. app.route('/reset/:token').get(mail.renderresetpage);
  210.  
  211. app.route('/reset/:token').post(mail.resetpassword);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement