當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Passport.use方法代碼示例

本文整理匯總了TypeScript中passport.Passport.use方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Passport.use方法的具體用法?TypeScript Passport.use怎麽用?TypeScript Passport.use使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在passport.Passport的用法示例。


在下文中一共展示了Passport.use方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: localSignin

  localSignin() {
    this.passport.use("local-signin", new passportLocal.Strategy({
      usernameField: "email",
      passwordField: "password",
      passReqToCallback: true
    }, (req: any, email: string, password: string, done: Function) => {
      process.nextTick(() => {
        User.findOne({ "local.email": email }, (err: any, user: any) => {
          if (err) {
            return done(err);
          }

          if (!user) {
            return done(null, false, req.flash("signin", "email|Couldn't find user"));
          }

          if (!user.verifyPassword(password)) {
            return done(null, false, req.flash("signin", "password|Invalid password"));
          }

          return done(null, user);
        });
      });
    }));
  }
開發者ID:snyderjk,項目名稱:TheCodeJo,代碼行數:25,代碼來源:passport.config.ts

示例2: localSignup

  localSignup() {
    this.passport.use("local-signup", new passportLocal.Strategy({
      usernameField: "email",
      passwordField: "password",
      passReqToCallback: true
    }, (req: any, email: string, password: string, done: Function) => {
      process.nextTick(() => {
        User.findOne( { "local.email": email }, (err: any, user: any) => {
          if (err) {
            return done(err);
          }

          if (user) {
            return done(null, false, req.flash("signup", "email|Email address already exists"));
          } else {
            let newUser = new User();
            newUser.local.email = email;
            newUser.local.password = newUser.generateHash(password);
            newUser.userImage = "http://localhost:3000/public/images/ninjaicon.png";

            newUser.save((saveErr: any) => {
              if (saveErr) {
                throw saveErr;
              }
              return done(null, newUser);
            });
          }
        });
      });
    }));
  }
開發者ID:snyderjk,項目名稱:TheCodeJo,代碼行數:31,代碼來源:passport.config.ts

示例3: setupPassport

function setupPassport(passport:Passport) {
	
	passport.use(new FacebookStrategy({
	    clientID: providers['facebook'].clientID,
	    clientSecret: providers['facebook'].clientSecret,
	    callbackURL: providers['facebook'].callbackURL
	  },facebookLogin
	));
	
    passport.use(new GoogleStrategy({
	    clientID: providers['google'].clientID,
	    clientSecret: providers['google'].clientSecret,
	    callbackURL: providers['google'].callbackURL
	  }
      , googleLogin
	));
};
開發者ID:ychebotarev,項目名稱:InColUn-v0,代碼行數:17,代碼來源:setupPassport.ts

示例4: function

function (model: DatabaseObject, passport: Passport): void {
  let opts: any = {}
  opts.secretOrKey = model.tokenSalt
  opts.jwtFromRequest = ExtractJwt.fromHeader('token')

  let strategy = new Strategy(opts, (jwtPayload, done) => {
    model.user.findOne({ _id: jwtPayload._doc._id }).exec()
    .then((account) => {
      account === undefined ? done(undefined, false) : done(undefined, account)
    }, (err) => {
      done(err, false)
    })
  })

  passport.use(strategy)
}
開發者ID:chipp972,項目名稱:stock_manager_api,代碼行數:16,代碼來源:auth.ts

示例5: setStrategy

    private setStrategy() {
        this._passport.use("local-signup", new localStrategy({
                // by default, local strategy uses username and password, we will override with email
                usernameField : "email",
                passwordField : "password",
                passReqToCallback : true // allows us to pass back the entire request to the callback
            },
            function(req, email, password, done) {

                // asynchronous
                // user.findOne wont fire unless data is sent back
                process.nextTick(function() {

                // find a user whose email is the same as the forms email
                // we are checking to see if the user trying to login already exists
                user.findOne({ "local.email" :  email }, function(err, user) {
                    // if there are any errors, return the error
                    if (err) {
                        return done(err);
                    }
                    // check to see if theres already a user with that email
                    if (user) {
                        return done(null, false, req.flash("signupMessage", "That email is already taken."));
                    } else {

                        // if there is no user with that email
                        // create the user
                        var newUser            = new user();

                        // set the user's local credentials
                        newUser.local.email    = email;
                        newUser.local.password = newUser.generateHash(password);

                        // save the user
                        newUser.save(function(err) {
                            if (err) {
                                throw err;
                            }
                            return done(null, newUser);
                        });
                    }
                });
            });
        }));
    }
開發者ID:kongbb,項目名稱:MyFinance,代碼行數:45,代碼來源:passport.ts


注:本文中的passport.Passport.use方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。