Permalink
Browse files

Additional Signup Validation

  • Loading branch information...
1 parent 018c780 commit 0d3129ff41c3e7d35321cf698a1e80534b11aaf3 @dstroot committed Feb 26, 2014
Showing with 14,146 additions and 50 deletions.
  1. +1 −1 .jshintrc
  2. +2 −1 bower.json
  3. +15 −15 config/passport.js
  4. +33 −1 controllers/user.js
  5. +16 −18 gulpfile.js
  6. +1 −1 less/bootstrap.less
  7. +9 −0 less/main.less
  8. +2 −2 package.json
  9. +84 −0 public/css/Skeleton.css
  10. +2 −2 public/css/Skeleton.min.css
  11. +1 −1 public/js/Skeleton.min.js
  12. +1 −1 public/js/Skeleton.min.js.map
  13. +36 −0 public/lib/complexify/README.md
  14. +182 −0 public/lib/complexify/complexify.js
  15. +3 −0 public/lib/complexify/jquery.complexify.banlist.js
  16. +182 −0 public/lib/complexify/jquery.complexify.js
  17. +25 −0 public/lib/mailcheck/.bower.json
  18. +20 −0 public/lib/mailcheck/LICENSE
  19. +187 −0 public/lib/mailcheck/README.md
  20. +14 −0 public/lib/mailcheck/bower.json
  21. BIN public/lib/mailcheck/doc/example.png
  22. +35 −0 public/lib/mailcheck/mailcheck.jquery.json
  23. +104 −0 public/lib/mailcheck/spec/lib/console-runner.js
  24. +20 −0 public/lib/mailcheck/spec/lib/jasmine-1.2.0/MIT.LICENSE
  25. +616 −0 public/lib/mailcheck/spec/lib/jasmine-1.2.0/jasmine-html.js
  26. +81 −0 public/lib/mailcheck/spec/lib/jasmine-1.2.0/jasmine.css
  27. +2,529 −0 public/lib/mailcheck/spec/lib/jasmine-1.2.0/jasmine.js
  28. +9,266 −0 public/lib/mailcheck/spec/lib/jquery.js
  29. +46 −0 public/lib/mailcheck/spec/lib/run_jasmine_test.coffee
  30. +261 −0 public/lib/mailcheck/spec/mailcheckSpec.js
  31. +29 −0 public/lib/mailcheck/spec/spec_runner.html
  32. +207 −0 public/lib/mailcheck/src/mailcheck.js
  33. +5 −0 public/lib/mailcheck/src/mailcheck.min.js
  34. +131 −7 views/account/signup.jade
View
@@ -1,5 +1,5 @@
{
- "maxerr" : 50, // {int} Maximum error before stopping
+ "maxerr" : 50, // {int} Maximum # of errors before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
View
@@ -5,6 +5,7 @@
"bootstrap": "~3.1.1",
"animate.css": "~3.0.0",
"moment": "~2.5.1",
- "odometer":"~0.4.6"
+ "odometer": "~0.4.6",
+ "mailcheck": "~1.0.3"
}
}
View
@@ -20,7 +20,7 @@ var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
* Serialize and Deserialize the User
*/
-passport.serializeUser(function(user, done) {
+passport.serializeUser(function (user, done) {
done(null, user.id);
});
@@ -34,10 +34,10 @@ passport.deserializeUser(function(id, done) {
* Local authentication
*/
-passport.use(new LocalStrategy({ usernameField: 'email' }, function(email, password, done) {
+passport.use(new LocalStrategy({ usernameField: 'email' }, function (email, password, done) {
User.findOne({ email: email }, function(err, user) {
if (!user) {
- return done(null, false, { message: 'Email ' + email + ' not found'});
+ return done(null, false, { message: 'Invalid email or password.' });
}
user.comparePassword(password, function(err, isMatch) {
if (isMatch) {
@@ -60,7 +60,7 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, function(email, passw
* Sign in with Facebook.
*/
-passport.use(new FacebookStrategy(config.facebook, function(req, accessToken, refreshToken, profile, done) {
+passport.use(new FacebookStrategy(config.facebook, function (req, accessToken, refreshToken, profile, done) {
if (req.user) {
User.findOne({ $or: [{ facebook: profile.id }, { email: profile.email }] }, function(err, existingUser) {
if (existingUser) {
@@ -82,7 +82,7 @@ passport.use(new FacebookStrategy(config.facebook, function(req, accessToken, re
}
});
} else {
- User.findOne({ facebook: profile.id }, function(err, existingUser) {
+ User.findOne({ facebook: profile.id }, function (err, existingUser) {
if (existingUser) {
// update the user's record with login timestamp
existingUser.activity.last_logon = Date.now();
@@ -112,7 +112,7 @@ passport.use(new FacebookStrategy(config.facebook, function(req, accessToken, re
* Sign in with GitHub.
*/
-passport.use(new GitHubStrategy(config.github, function(req, accessToken, refreshToken, profile, done) {
+passport.use(new GitHubStrategy(config.github, function (req, accessToken, refreshToken, profile, done) {
if (req.user) {
User.findOne({ $or: [{ github: profile.id }, { email: profile.email }] }, function(err, existingUser) {
if (existingUser) {
@@ -134,7 +134,7 @@ passport.use(new GitHubStrategy(config.github, function(req, accessToken, refres
}
});
} else {
- User.findOne({ github: profile.id }, function(err, existingUser) {
+ User.findOne({ github: profile.id }, function (err, existingUser) {
if (existingUser) {
// update the user's record with login timestamp
existingUser.activity.last_logon = Date.now();
@@ -164,7 +164,7 @@ passport.use(new GitHubStrategy(config.github, function(req, accessToken, refres
* Sign in with Twitter.
*/
-passport.use(new TwitterStrategy(config.twitter, function(req, accessToken, tokenSecret, profile, done) {
+passport.use(new TwitterStrategy(config.twitter, function (req, accessToken, tokenSecret, profile, done) {
if (req.user) {
User.findOne({ twitter: profile.id }, function(err, existingUser) {
if (existingUser) {
@@ -185,11 +185,11 @@ passport.use(new TwitterStrategy(config.twitter, function(req, accessToken, toke
}
});
} else {
- User.findOne({ twitter: profile.id }, function(err, existingUser) {
+ User.findOne({ twitter: profile.id }, function (err, existingUser) {
if (existingUser) {
// update the user's record with login timestamp
existingUser.activity.last_logon = Date.now();
- existingUser.save(function(err) {
+ existingUser.save(function (err) {
if (err) {
return (err);
}
@@ -231,7 +231,7 @@ passport.use(new TwitterStrategy(config.twitter, function(req, accessToken, toke
* Sign in with Google.
*/
-passport.use(new GoogleStrategy(config.google, function(req, accessToken, refreshToken, profile, done) {
+passport.use(new GoogleStrategy(config.google, function (req, accessToken, refreshToken, profile, done) {
if (req.user) {
User.findOne({ $or: [{ google: profile.id }, { email: profile.email }] }, function(err, existingUser) {
if (existingUser) {
@@ -252,7 +252,7 @@ passport.use(new GoogleStrategy(config.google, function(req, accessToken, refres
}
});
} else {
- User.findOne({ google: profile.id }, function(err, existingUser) {
+ User.findOne({ google: profile.id }, function (err, existingUser) {
if (existingUser) {
// update the user's record with login timestamp
existingUser.activity.last_logon = Date.now();
@@ -328,7 +328,7 @@ passport.use('foursquare', new OAuth2Strategy({
* Login Required middleware.
*/
-exports.isAuthenticated = function(req, res, next) {
+exports.isAuthenticated = function (req, res, next) {
if (req.isAuthenticated()) {
return next();
} else {
@@ -341,7 +341,7 @@ exports.isAuthenticated = function(req, res, next) {
* Authorization Required middleware.
*/
-exports.isAuthorized = function(req, res, next) {
+exports.isAuthorized = function (req, res, next) {
var provider = req.path.split('/').slice( -1 )[0];
if (_.findWhere(req.user.tokens, { kind: provider })) {
next();
@@ -354,7 +354,7 @@ exports.isAuthorized = function(req, res, next) {
* Check if the account is an Administrator
*/
-exports.isAdministrator = function(req, res, next) {
+exports.isAdministrator = function (req, res, next) {
// make sure we are logged in first
if (req.isAuthenticated()) {
//user must be be an administrator
View
@@ -13,6 +13,11 @@ var User = require('../models/User');
module.exports.controller = function(app) {
+/**
+ * GET /login
+ * Render login page
+ */
+
app.get('/login', function(req, res) {
if (req.user) {
return res.redirect('/');
@@ -22,7 +27,14 @@ module.exports.controller = function(app) {
});
});
+/**
+ * POST /login
+ * Log the user in
+ */
+
app.post('/login', function(req, res, next) {
+
+ // Validate the form fields
req.assert('email', 'Email is not valid').isEmail();
req.assert('password', 'Password cannot be blank').notEmpty();
var errors = req.validationErrors();
@@ -32,6 +44,7 @@ module.exports.controller = function(app) {
return res.redirect('/login');
}
+ // Authenticate the user
passport.authenticate('local', function(err, user, info) {
if (err) {
return next(err);
@@ -61,11 +74,21 @@ module.exports.controller = function(app) {
});
+/**
+ * GET /logout
+ * Log the user out
+ */
+
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
+ /**
+ * GET /signup
+ * Render signup page
+ */
+
app.get('/signup', function(req, res) {
if (req.user) {
return res.redirect('/');
@@ -75,17 +98,24 @@ module.exports.controller = function(app) {
});
});
+ /**
+ * POST /signup
+ *
+ */
+
app.post('/signup', function(req, res, next) {
+
+ // Validate form fields
req.assert('email', 'Email is not valid').isEmail();
req.assert('password', 'Password must be at least 4 characters long').len(4);
req.assert('confirmPassword', 'Passwords do not match').equals(req.body.password);
var errors = req.validationErrors();
-
if (errors) {
req.flash('errors', errors);
return res.redirect('/signup');
}
+ // Create a new account
var user = new User({
'profile.name': req.body.name,
email: req.body.email,
@@ -99,6 +129,8 @@ module.exports.controller = function(app) {
}
return res.redirect('/signup');
}
+
+ // log the user in
req.logIn(user, function(err) {
if (err) {
return next(err);
View
@@ -9,22 +9,23 @@
*/
var gulp = require('gulp');
-var clean = require('gulp-clean');
+var size = require('gulp-size');
+var jscs = require('gulp-jscs'); // https://www.npmjs.org/package/jscs
var less = require('gulp-less');
-var nodemon = require('gulp-nodemon'); // https://www.npmjs.org/package/gulp-nodemon
-var jshint = require('gulp-jshint');
+var clean = require('gulp-clean');
var concat = require('gulp-concat');
+var header = require('gulp-header');
var uglify = require('gulp-uglify');
+var notify = require('gulp-notify'); // DOES NOT WORK ON WINDOWS
var rename = require('gulp-rename');
+var jshint = require('gulp-jshint'); // https://github.com/wearefractal/gulp-jshint
+var stylish = require('jshint-stylish');
var changed = require('gulp-changed'); // https://github.com/sindresorhus/gulp-changed
-var autoprefixer = require('gulp-autoprefixer');
+var nodemon = require('gulp-nodemon'); // https://www.npmjs.org/package/gulp-nodemon
var imagemin = require('gulp-imagemin');
-var size = require('gulp-size');
-var jscs = require('gulp-jscs'); // https://www.npmjs.org/package/jscs
var minifycss = require('gulp-minify-css'); // https://www.npmjs.org/package/gulp-minify-css
-var notify = require('gulp-notify'); // DOES NOT WORK ON WINDOWS
var livereload = require('gulp-livereload');
-var header = require('gulp-header');
+var autoprefixer = require('gulp-autoprefixer');
/**
* Banner
@@ -45,17 +46,18 @@ var banner = ['/**',
var paths = {
clean: [
+ '!public/js/main.js',
'public/js/**/*.js',
'public/js/**/*.min.js',
- '!public/js/main.js',
'public/css/**/*.css',
'public/css/**/*.min.css'
],
js: [
- // Bootstrap: ==============================
+ // Bootstrap ==============================
// Enable/disable as needed but
// only turn on .js that is needed
// on *every* page. No bloat!
+ // =========================================
'public/lib/bootstrap/js/transition.js',
'public/lib/bootstrap/js/alert.js',
// 'public/lib/bootstrap/js/button.js',
@@ -80,10 +82,6 @@ var paths = {
'app_cluster.js',
'gulpfile.js'
],
- less: [
- 'less/main.less',
- 'less/bootstrap.less'
- ],
images: 'public/img/**/*'
};
@@ -122,8 +120,8 @@ gulp.task('styles', function() {
gulp.task('lint', function() {
gulp.src(paths.lint) // Read .js files
- .pipe(jshint('.jshintrc')) // Lint .js files
- .pipe(jshint.reporter('default')) // Specify a reporter for JSHint
+ .pipe(jshint()) // Lint .js files
+ .pipe(jshint.reporter(stylish)) // Specify a reporter for JSHint
.pipe(jscs()) // Check code style
.pipe(notify({ onLast: true, message: 'Lint task complete' }));
});
@@ -137,7 +135,7 @@ gulp.task('scripts', function() {
.pipe(concat(pkg.name + '.js')) // Concatenate .js files into "packagename.js"
.pipe(gulp.dest('./public/js')) // Save main.js here
.pipe(rename({suffix: '.min'})) // Add .min suffix
- .pipe(uglify({ outSourceMap: true })) // Minify the .js
+ .pipe(uglify({ outSourceMap: true })) // Minify the .js
.pipe(header(banner, { pkg : pkg } )) // Add banner
.pipe(size()) // What size are we at?
.pipe(gulp.dest('./public/js')) // Save minified .js
@@ -161,7 +159,7 @@ gulp.task('images', function() {
* Build Task
*/
-gulp.task('build', ['clean', 'styles', 'scripts', 'images']);
+gulp.task('build', ['clean', 'styles', 'scripts', 'images', 'lint']);
/**
* Watch Files (Rerun/reload when a file changes)
View
@@ -42,7 +42,7 @@
@import "../public/lib/bootstrap/less/jumbotron.less";
// @import "../public/lib/bootstrap/less/thumbnails.less";
@import "../public/lib/bootstrap/less/alerts.less";
-// @import "../public/lib/bootstrap/less/progress-bars.less";
+@import "../public/lib/bootstrap/less/progress-bars.less";
// @import "../public/lib/bootstrap/less/media.less";
// @import "../public/lib/bootstrap/less/list-group.less";
@import "../public/lib/bootstrap/less/panels.less";
View
@@ -444,7 +444,16 @@ h4, h5, h6,
tbody>tr>td {
border-top: 0px;
}
+}
+
+/**
+ * Signup page
+ */
+#complexityLabel {
+ width: 100%;
+ text-align: center;
+ margin-top: -40px;
}
/**
View
@@ -1,6 +1,6 @@
{
"private": true,
- "version": "0.0.1-42",
+ "version": "0.0.1-43",
"name": "Skeleton",
"company": "Skeleton, Inc.",
"subdomain": "skeleton-app",
@@ -80,7 +80,7 @@
"gulp-less": "~1.2.1",
"gulp-clean": "~0.2.4",
"gulp-uglify": "~0.2.1",
- "gulp-jshint": "~1.4.2",
+ "gulp-jshint": "~1.5.0",
"gulp-minify-css": "~0.3.0",
"gulp-watch": "~0.5.0",
"gulp-autoprefixer": "0.0.6",
Oops, something went wrong.

0 comments on commit 0d3129f

Please sign in to comment.