Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST /login 500 #16

Open
zhaobc opened this issue May 24, 2018 · 0 comments
Open

POST /login 500 #16

zhaobc opened this issue May 24, 2018 · 0 comments

Comments

@zhaobc
Copy link

zhaobc commented May 24, 2018

I run the sever is ok at the first time,but when I try to login after a time.That will be "POST /login 500 217.833 ms - 1355".My code:

passport.use(
        'local-login',
        new LocalStrategy({
            // by default, local strategy uses username and password, we will override with email
            usernameField : 'username',
            passwordField : 'password',
            passReqToCallback : true // allows us to pass back the entire request to the callback
        },
        function(req, username, password, done) { // callback with email and password from our form
            connection.query("SELECT * FROM palcan_datacenter.user_tbl WHERE name = ?;",[username],function(err,rows){
                if (err){
                    return done(err);
                }

                if (!rows.length) {
                    return done(null, false, req.flash('loginMessage', 'No user here.')); // req.flash is the way to set flashdata using connect-flash
                }
                
                // if the user is found but the password is wrong
                if (!( rows[0].password == password)){
                    return done(null, false, req.flash('loginMessage', 'Passport is not correct.')); // create the loginMessage and save it to session as flashdata
                }
                var json={};
                json.id=rows[0].uid;
                json.name=rows[0].name;
                json.password=rows[0].password;
                return done(null, json);
            });
        })
    );`
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant