Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Fixing errors style
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Dec 12, 2013
1 parent d36b852 commit f8ac701
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
13 changes: 12 additions & 1 deletion app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,23 @@ exports.session = function(req, res) {
*/
exports.create = function(req, res) {
var user = new User(req.body);
var message = null;

user.provider = 'local';
user.save(function(err) {
if (err) {
console.log(err);
switch(err.code){
case 11000:
case 11001:
message = 'Username already exists';
break;
default:
message = 'Please fill all the required fields';
}

return res.render('users/signup', {
errors: err.errors,
message: message,
user: user
});
}
Expand Down
5 changes: 2 additions & 3 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var UserSchema = new Schema({
type: String,
unique: true
},
provider: String,
hashed_password: String,
provider: String,
salt: String,
facebook: {},
twitter: {},
Expand Down Expand Up @@ -116,8 +116,7 @@ UserSchema.methods = {
* @api public
*/
encryptPassword: function(password) {
if (!password) return '';
if (!this.salt) return '';
if (!password || !this.salt) return '';
salt = new Buffer(this.salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}
Expand Down
4 changes: 4 additions & 0 deletions app/views/users/auth.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ block content
a(href="/auth/google")
img(src="/img/icons/google.png")
.span6
if message && message.length
.fade.in.alert.alert-error
button.close(type="button", data-dismiss="alert") ×
strong #{message}
block auth
9 changes: 0 additions & 9 deletions app/views/users/signin.jade
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
extends auth

block auth
if message.length > 0
.fade.in.alert.alert-block.alert-error
p #{message}
a.close(data-dismiss="alert", href="javascript:void(0)") x
ul
each error in errors
li= error


form.signin.form-horizontal(action="/users/session", method="post")
.control-group
label.control-label(for='email') Email
Expand Down
6 changes: 3 additions & 3 deletions config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ module.exports = function(app, passport, auth) {
app.get('/signin', users.signin);
app.get('/signup', users.signup);
app.get('/signout', users.signout);
app.get('/users/me', users.me);

//Setting up the users api
app.post('/users', users.create);

//Setting the local strategy route
app.post('/users/session', passport.authenticate('local', {
failureRedirect: '/signin',
failureFlash: 'Invalid email or password.'
failureFlash: true
}), users.session);

app.get('/users/me', users.me);

//Setting the facebook oauth routes
app.get('/auth/facebook', passport.authenticate('facebook', {
scope: ['email', 'user_about_me'],
Expand Down

0 comments on commit f8ac701

Please sign in to comment.