Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post("/api/loginAuth", function(req, res, next) {
- if(!req.body.email) {
- return next(JSON.stringify({"status": "error", "message": "A username must be provided"}));
- }
- if(!req.body.password) {
- return next(JSON.stringify({"status": "error", "message": "A password must be provided"}));
- }
- req.body.loginAuth = true;
- User.advancedSearch(req.body, function(error, user) {
- if(error) {
- return res.status(400).send(error);
- }
- console.log('user: ' + JSON.stringify(user));
- var x = [];
- x = user;
- if (x.length === 0) {
- return res.status(400).send('The username entered does not exist');
- }
- if(!User.validatePassword(req.body.password, user[0].password)) {
- return res.status(400).send("The password entered is invalid");
- }
- if (!user[0].login.emailVerified) {
- return res.status(400).send("The username (email) entered is not yet verified, please verify before logging in.");
- }
- User.addLoginTime(user[0].uuid, function(error, result) {
- if(error) {
- return res.status(400).send(error);
- }
- Session.create(user[0].uuid, function(error, result) {
- if(error) {
- return res.status(400).send(error);
- }
- res.send({sessionID: result.sessionID, expiry: result.expiry});
- });
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement