Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- passport.use('local-signup', new localStrategy(
- {
- usernameField : 'username',
- passwordField : 'password',
- passReqToCallback: true // allows us to pass back the entire request to the callback
- },
- function(req, username, password, done) {
- // asynchronous
- // userModel.findOne wont fire unless data is sent back
- process.nextTick(function() {
- var recaptcha = nconf.get('recaptcha');
- if (recaptcha && req.recaptcha.error) {
- return done(null, false, req.flash('error', 'The recaptcha could not be verified.'));
- }
- // 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
- userModel.findOne({ 'local.username': username }, function(err, user) {
- // if there are any errors, return the error
- if (err)
- console.log(err);
- // return done(err);
- // check to see if there's already a user with that email
- if (user) {
- return done(null, false, req.flash('error', 'This user already exists.'));
- } else {
- // if there is no user with that email
- // create the user
- var newUser = new userModel();
- // set the user's local credentials
- newUser.local.username = username;
- newUser.local.password = newUser.generateHash(password);
- newUser.data.email = req.body.email;
- newUser.data.phone = req.body.phone;
- // save the user
- newUser.save(function(err) {
- if (err)
- throw err;
- return done(null, newUser);
- });
- }
- });
- });
- })
- );
- router.post('/register', middleware.recaptcha.verify, auth.register);
- main.register = function (req, res, next) {
- var data = {
- error: req.flash('error')[ 0 ],
- recaptcha: req.recaptcha
- };
- res.render('register', data);
- };
- /*
- global module,
- require
- */
- var mongoose = require('mongoose'),
- nconf = require('nconf'),
- path = require('path'),
- fs = require('fs'),
- bcrypt = require('bcrypt-nodejs');
- // define the schema for our user model
- var userSchema = mongoose.Schema({
- local: {
- username: String,
- password: String
- },
- settings: {
- showLastAuctions: Boolean,
- useGravatarImage: { type: Boolean, default: false }
- },
- data: {
- admin: { type: Boolean, default: false },
- email: String,
- phone: String,
- profileImg: String,
- realname: String,
- birthday: String,
- registerDate: Date,
- status: String,
- paymentUnits: Number,
- auctions: [ {
- id: String,
- name: String,
- date: Date,
- endPrice: String
- } ],
- connections: [ {
- remoteAddress: String,
- hostname: String,
- location: String,
- lastSeen: Date
- } ]
- }
- }//,{
- // collection: 'users'
- //}
- );
- module.exports = mongoose.model('User', userSchema);
Add Comment
Please, Sign In to add comment