Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const AlteraUserpassword = async (connection, req, res) => {
- req.body.password = await hashpass(req.body.password)
- const user = await User.findUser(connection, req.body.username)
- if(!await bcrypt.compare(req.body.oldpassword, user.password)){
- res.json({'valid': false});
- res.end('{"error" : "Updated Successfully", "status" : 200}');
- }
- else{
- const user= await User.AlteraPasswordUser(connection, req.body)
- if(!user){
- console.log("Nao Deu");
- res.json({'valid': false});
- res.end('{error" : "Updated Successfully", "status" : 200}');
- }else{
- console.log("Deu")
- console.log(req.body.username)
- res.json({'valid': true});
- res.end('{"success" : "Updated Successfully", "status" : 200}');
- }
- }
- }
- const express = require('express')
- const router = express.Router()
- const connection = require('../../Config/database')
- const controllerAdmin = require('../../controllers/Administration')
- const controlleruser = require('../../controllers/login')
- router.get('/Administration/perfil', (req, res) => controllerAdmin.findcidade2(connection, req, res))
- router.post('/Administration/perfil',(req, res) =>controlleruser.AlteraUserpassword(connection, req, res))
- //router.get('/Administration/perfil/', (req, res) => res.render('Administration/perfil',{username:res.locals.user.username,email:res.locals.user.mail}))
- module.exports = app => app.use('/', router)
- $(document).ready(function() {
- framework: 'bootstrap',
- $('.perfilupdate').bootstrapValidator({
- // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
- feedbackIcons: {
- valid: 'glyphicon glyphicon-ok',
- invalid: 'glyphicon glyphicon-remove',
- validating: 'glyphicon glyphicon-refresh'
- },
- fields: {
- oldpassword: {
- validators: {
- stringLength: {
- min: 8,
- },
- notEmpty: {
- message: 'Insira Password'
- }
- }
- },
- password: {
- validators: {
- stringLength: {
- min: 8,
- },
- identical: {
- field: 'password_again',
- message: 'The password and its confirm are not the same'
- },
- notEmpty: {
- message: 'Insira Password'
- }
- }
- },
- password_again: {
- validators: {
- stringLength: {
- min: 8,
- },
- identical: {
- field: 'password',
- message: 'The password and its confirm are not the same'
- },
- notEmpty: {
- message: 'password'
- },
- password_again : 'password must match'
- }
- },
- }
- /* submitHandler: function(form) {
- $.ajax({
- url : 'AlteraUserpassword',
- message : 'Username has been taken',
- result: {
- type : 'oldpassword',
- datatype: "json",
- },
- type : 'POST',
- success: function (result) { console.log(result); if(result.status == 200){ self.isEditMode(!self.isEditMode()); } }, error: function(result){ console.log(result); } });
- }
- */
- })
- });
Add Comment
Please, Sign In to add comment