Guest User

Untitled

a guest
Aug 23rd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. const AlteraUserpassword = async (connection, req, res) => {
  2. req.body.password = await hashpass(req.body.password)
  3. const user = await User.findUser(connection, req.body.username)
  4. if(!await bcrypt.compare(req.body.oldpassword, user.password)){
  5. res.json({'valid': false});
  6. res.end('{"error" : "Updated Successfully", "status" : 200}');
  7. }
  8. else{
  9. const user= await User.AlteraPasswordUser(connection, req.body)
  10. if(!user){
  11. console.log("Nao Deu");
  12. res.json({'valid': false});
  13. res.end('{error" : "Updated Successfully", "status" : 200}');
  14.  
  15. }else{
  16.  
  17. console.log("Deu")
  18. console.log(req.body.username)
  19. res.json({'valid': true});
  20. res.end('{"success" : "Updated Successfully", "status" : 200}');
  21. }
  22. }
  23. }
  24.  
  25. const express = require('express')
  26. const router = express.Router()
  27. const connection = require('../../Config/database')
  28. const controllerAdmin = require('../../controllers/Administration')
  29. const controlleruser = require('../../controllers/login')
  30. router.get('/Administration/perfil', (req, res) => controllerAdmin.findcidade2(connection, req, res))
  31. router.post('/Administration/perfil',(req, res) =>controlleruser.AlteraUserpassword(connection, req, res))
  32. //router.get('/Administration/perfil/', (req, res) => res.render('Administration/perfil',{username:res.locals.user.username,email:res.locals.user.mail}))
  33.  
  34. module.exports = app => app.use('/', router)
  35.  
  36.  
  37.  
  38. $(document).ready(function() {
  39. framework: 'bootstrap',
  40.  
  41. $('.perfilupdate').bootstrapValidator({
  42. // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
  43. feedbackIcons: {
  44. valid: 'glyphicon glyphicon-ok',
  45. invalid: 'glyphicon glyphicon-remove',
  46. validating: 'glyphicon glyphicon-refresh'
  47. },
  48. fields: {
  49. oldpassword: {
  50.  
  51. validators: {
  52. stringLength: {
  53. min: 8,
  54. },
  55.  
  56. notEmpty: {
  57. message: 'Insira Password'
  58. }
  59. }
  60.  
  61. },
  62. password: {
  63.  
  64. validators: {
  65. stringLength: {
  66. min: 8,
  67. },
  68. identical: {
  69. field: 'password_again',
  70. message: 'The password and its confirm are not the same'
  71. },
  72.  
  73. notEmpty: {
  74. message: 'Insira Password'
  75. }
  76. }
  77.  
  78. },
  79. password_again: {
  80.  
  81. validators: {
  82. stringLength: {
  83. min: 8,
  84. },
  85. identical: {
  86. field: 'password',
  87. message: 'The password and its confirm are not the same'
  88. },
  89. notEmpty: {
  90. message: 'password'
  91. },
  92. password_again : 'password must match'
  93. }
  94. },
  95.  
  96.  
  97.  
  98. }
  99. /* submitHandler: function(form) {
  100. $.ajax({
  101. url : 'AlteraUserpassword',
  102. message : 'Username has been taken',
  103. result: {
  104. type : 'oldpassword',
  105. datatype: "json",
  106. },
  107. type : 'POST',
  108. success: function (result) { console.log(result); if(result.status == 200){ self.isEditMode(!self.isEditMode()); } }, error: function(result){ console.log(result); } });
  109.  
  110. }
  111. */
  112.  
  113. })
  114.  
  115. });
Add Comment
Please, Sign In to add comment