Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function signup(req, res) {
- res.render('signup');
- }
- function signupProcess(req, res) {
- //we create a new User to be saved into the database
- var User = require('../../user/models/user');
- var user = new User();
- var utilities = require('../../core/utilities');
- //we check whether all the fields were filled
- //a first check is performed on form but two checks are better than one...
- if (typeof req.body.firstName === 'string' &&
- typeof req.body.lastName === 'string' &&
- typeof req.body.username === 'string' &&
- typeof req.body.email === 'string' &&
- typeof req.body.password === 'string' &&
- req.body.firstName != '' &&
- req.body.lastName != '' &&
- req.body.username != '' &&
- req.body.email != '' &&
- req.body.password != '' &&
- utilities.validateEmail(req.body.email)) {
- //we create an object with all the data
- user.local.firstName = req.body.firstName;
- user.local.lastName = req.body.lastName;
- user.local.username = req.body.username;
- user.local.email = req.body.email;
- user.local.password = req.body.password;
- //we check whether this email already exists
- User.findOne({"local.email": req.body.email }, function(err, existingUser) {
- if (existingUser) {
- res.redirect('/signup');
- }
- else {
- user.save(function(err, admin) {
- if (err) return next(err);
- res.redirect('/signin');
- });
- }
- });
- }
- //there are errors on the validation
- //issue an error to the user
- else {
- res.status(400).redirect('/signup');
- }
- }
- module.exports.signup = signup;
- module.exports.signupProcess = signupProcess;
Add Comment
Please, Sign In to add comment