Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var passport = require('passport');
- var LocalStrategy = require('passport-local').Strategy;
- var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
- var expressValidator = require('express-validator');
- var bodyParser = require('body-parser');
- var User = require('./user');
- var configAuth = require('./auth');
- // Login
- passport.use('login', new LocalStrategy({
- usernameField: 'email',
- passwordField: 'password',
- passReqToCallback: true
- },
- function (req, email, password, done) {
- console.log("Im here now!");
- if (email) {
- console.log("toLowerCase")
- email = email.toLowerCase();
- }
- process.nextTick(function () {
- User.findOne({ 'email': email }, function (err, user) {
- if (err) {
- return done(err);
- }
- if (!user) {
- console.log('User Not Found with email ' + email);
- return done(null, false);
- }
- if (!user.validPassword(password)) {
- console.log('Invalid Password');
- return done(null, false);
- }
- return done(null, user);
- });
- });
- }));
- router.post('/login', passport.authenticate('login', {
- successRedirect: '/auth/success',
- failureRediret: '/auth/failure'
- }));
- <form ng-submit="doLogin()">
- <div class="list">
- <label class="item item-input">
- <span class="input-label">Username</span>
- <input type="email" data-type="text" ng-model="loginData.email" name="email">
- </label>
- <label class="item item-input">
- <span class="input-label">Password</span>
- <input type="password" ng-model="loginData.password" name="password">
- </label>
- <label class="item">
- <button class="button button-block button-positive" type="submit">Log in</button>
- </label>
- </div>
- </form>
- $scope.doLogin = function() {
- var email= $scope.loginData.email;
- var password = $scope.loginData.password;
- console.log('Doing login', $scope.loginData);
- $http({
- method: 'POST',
- url: 'http://localhost:8000/auth/login',
- data: {email: email, password: password},
- headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Access-
- Control-Allow-Origin': '*'}
- });
- };
- app.use('/auth', routes);
- app.use(passport.initialize());
- app.use(passport.session());
- router.post('/login', passport.authenticate('login', {
- successRedirect: '/auth/success',
- failureRediret: '/auth/failure'
- }));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement