Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

update password using comparePassword() Method

router.put('/password',verifyToken,UserController.updatePassword);


async updatePassword(req, res) {
        const { user } = req;
        const { currentPassword, newPassword } = req.body;

        const matched = await user.comparePassword(currentPassword);
        if (!matched) {
            return res.warn('', req.__('PASSWORD_MATCH_FAILURE'));
        }
        const matcheAddedPassword = await user.comparePassword(newPassword);
        if(matcheAddedPassword){
            return res.warn('','Old password and new passowrd can not be same');
        }


        user.password = newPassword;
        await user.save();

        return res.success('', 'Password updated successfully.');
    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: file-loader support json file 
Javascript :: regex city and state 
Javascript :: getx navigation 
Javascript :: clean my react app 
Javascript :: deleting an instance in sequelize 
Javascript :: how to call javascript function with parameter in c# 
Javascript :: div goind down 
Javascript :: split by space capital letter or underscore javascript 
Javascript :: class constructor syntax 
Javascript :: obtain only integer not decimal js 
Javascript :: in in sequelize 
Javascript :: js how to sort array by object value 
Javascript :: onselect in zebra datepicker 
Javascript :: json schema bsp 
Javascript :: how to use socket io in production 
Javascript :: bash json creator 
Javascript :: get image from s3 bucket angular 
Javascript :: convert days to weeks and days javascript typescript 
Javascript :: javascript append to object 
Javascript :: service worker self.clients 
Javascript :: js any array member true 
Javascript :: react-intersection-observer 
Javascript :: rest parameters 
Javascript :: canvas rounded corners 
Javascript :: call dynamic var name javascript 
Javascript :: how to assign empty function in react component props 
Javascript :: .tolowercase 
Javascript :: cypress check element has an attribute 
Javascript :: array from js 
Javascript :: javascript reduce return array 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =