This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
777 additions
and
694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,103 @@ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
var mongoose = require('mongoose'), | ||
User = mongoose.model('User'); | ||
|
||
//exports.signin = function (req, res) {} | ||
|
||
/** | ||
* Auth callback | ||
*/ | ||
exports.authCallback = function (req, res, next) { | ||
res.redirect('/'); | ||
exports.authCallback = function(req, res, next) { | ||
res.redirect('/'); | ||
}; | ||
|
||
/** | ||
* Show login form | ||
*/ | ||
exports.signin = function (req, res) { | ||
res.render('users/signin', { | ||
title: 'Signin', | ||
message: req.flash('error') | ||
}); | ||
exports.signin = function(req, res) { | ||
res.render('users/signin', { | ||
title: 'Signin', | ||
message: req.flash('error') | ||
}); | ||
}; | ||
|
||
/** | ||
* Show sign up form | ||
*/ | ||
exports.signup = function (req, res) { | ||
res.render('users/signup', { | ||
title: 'Sign up', | ||
user: new User() | ||
}); | ||
exports.signup = function(req, res) { | ||
res.render('users/signup', { | ||
title: 'Sign up', | ||
user: new User() | ||
}); | ||
}; | ||
|
||
/** | ||
* Logout | ||
*/ | ||
exports.signout = function (req, res) { | ||
req.logout(); | ||
res.redirect('/'); | ||
exports.signout = function(req, res) { | ||
req.logout(); | ||
res.redirect('/'); | ||
}; | ||
|
||
/** | ||
* Session | ||
*/ | ||
exports.session = function (req, res) { | ||
res.redirect('/'); | ||
exports.session = function(req, res) { | ||
res.redirect('/'); | ||
}; | ||
|
||
/** | ||
* Create user | ||
*/ | ||
exports.create = function (req, res) { | ||
var user = new User(req.body); | ||
exports.create = function(req, res) { | ||
var user = new User(req.body); | ||
|
||
user.provider = 'local'; | ||
user.save(function (err) { | ||
if (err) { | ||
return res.render('users/signup', { errors: err.errors, user: user }); | ||
} | ||
req.logIn(user, function(err) { | ||
if (err) return next(err); | ||
return res.redirect('/'); | ||
user.provider = 'local'; | ||
user.save(function(err) { | ||
if (err) { | ||
return res.render('users/signup', { | ||
errors: err.errors, | ||
user: user | ||
}); | ||
} | ||
req.logIn(user, function(err) { | ||
if (err) return next(err); | ||
return res.redirect('/'); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
/** | ||
* Show profile | ||
*/ | ||
exports.show = function (req, res) { | ||
var user = req.profile; | ||
exports.show = function(req, res) { | ||
var user = req.profile; | ||
|
||
res.render('users/show', { | ||
title: user.name, | ||
user: user | ||
}); | ||
res.render('users/show', { | ||
title: user.name, | ||
user: user | ||
}); | ||
}; | ||
|
||
/** | ||
* Send User | ||
*/ | ||
exports.me = function (req, res) { | ||
res.jsonp(req.user || null); | ||
exports.me = function(req, res) { | ||
res.jsonp(req.user || null); | ||
}; | ||
|
||
/** | ||
* Find user by id | ||
*/ | ||
exports.user = function (req, res, next, id) { | ||
User | ||
.findOne({ _id : id }) | ||
.exec(function (err, user) { | ||
if (err) return next(err); | ||
if (!user) return next(new Error('Failed to load User ' + id)); | ||
req.profile = user; | ||
next(); | ||
}); | ||
}; | ||
exports.user = function(req, res, next, id) { | ||
User | ||
.findOne({ | ||
_id: id | ||
}) | ||
.exec(function(err, user) { | ||
if (err) return next(err); | ||
if (!user) return next(new Error('Failed to load User ' + id)); | ||
req.profile = user; | ||
next(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.