javascript 护照:当地战略

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 护照:当地战略相关的知识,希望对你有一定的参考价值。

const LocalStrategy = require("passport-local").Strategy;
const UserController = require("@v1-controllers/user.controller");

module.exports = new LocalStrategy(
	{
		usernameField: "email",
		passwordField: "password",
		passReqToCallback: true // allows us to pass back the entire request to the callback
	},
	(req, email, password, done) => {
		process.nextTick(() => {
			UserController.authenticateUser(email).then((user, userError) => {
				if (userError) {
					return done(userError);
				}

				// check if email is already in database
				if (user) {
					return done(null, false, req.flash("signupMessage", "Email has already been registered."));
				}

				// add user to database
				new Promise(resolve => {
					const inputUser = {
						email: req.body.email,
						password: req.body.password,
					};

					resolve(UserController.addUser(inputUser));
				});
			});
		});
	}
);
const LocalStrategy = require("passport-local").Strategy;
const UserController = require("@v1-controllers/user.controller");
const bcrypt = require("bcrypt-nodejs");

module.exports = new LocalStrategy(
	{
		usernameField: "email",
		passwordField: "password",
		passReqToCallback : true, // allows us to pass back the entire request to the callback
	},
	(req, email, password, done) => {
		UserController.authenticateUser(email)
			.then((user, error) => {
				if (error) {
					return done(error);
				}

        // check if user exists
				if (!user) {
					return done(null, false, req.flash("loginMessage", "User is not in our system."));
				}

				// compare hashed password input to hashed password from database
				if (!bcrypt.compareSync(password, user.password)) {
					return done(null, false, req.flash("loginMessage", "Password is incorrect."));
				}

				return done(null, user);
			});
	}
);

passport.use("local-login", require("./localLogin"));
passport.use("local-signup", require("./localSignup"));

以上是关于javascript 护照:当地战略的主要内容,如果未能解决你的问题,请参考以下文章

旅行必备清单

中国公民去美国纽约

javascript 护照 - 中间件持票人

javascript 节点护照状态

javascript 护照:isLoggedIn

javascript 默认护照-facebook