简体   繁体   中英

Updating password using 'PUT' method

can someone help me to understand how to use the query function created to update a password in my database?

here is the query function in question

async function updatePassword(req, res) {
return db.none('UPDATE user_account SET password = $1 WHERE email = $2',
        [req.body.password, req.body.email])
    .then(function () {
        res.status(200)
            .json({
                status: 'success',
                message: 'Updated user'
            });
    })
    .catch(error => {
        console.log(error)
    });

}

here is what I tried to do with fetch method put

resetPassword(){
            fetch('http://url/example', {
                    method: 'PUT',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        email: this.email,
                        password: this.passwordReset,
                        
                    }),
            })
        // Converting to JSON
        .then(response => response.json())
        // Displaying results to console
        .then(json => console.log(json));       
        },

no error "{status: 'success', message: 'Updated user'}"

but nothing has changed in my database

edit : problem solved thanks everyone

'UPDATE user_account SET password = $1 WHERE email = $2' 你传递了 req.params 和 req.body 所以在你的情况下 req.params.email 传递了它的执行和成功,我认为这是使用两者的坏主意一。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM