127.0.0.1:8000 watch-together / master server / routes / api / account / login.js
master

Tree @master (Download .tar.gz)

login.js @masterraw · history · blame

const utils = require('../../../utils');
const passport = require('passport');

module.exports = {
    post: {
        "": [{
            rate_limit: false,
            harsh_rate_limit: true,
            auth: false,
            captcha: true
        }, function(req, res, next) {
            utils.validate.keys(req.body, [
                ["email", utils.validate.email]
            ]).then(function() {
                passport.authenticate('local', function(err, user, info) {
                    if (err) {
                        return next(err);
                    }
                    if (!user) {
                        return utils.handle_err.res(res)(info.message);
                    }

                    req.logIn(user, function(err) {
                        if (err) {
                            return next(err);
                        }

                        res.send(utils.ok({
                            user_id: user.user_id
                        }));
                    });
                })(req, res, next);
            }).catch(utils.handle_err.res(res));
        }]
    }
}