summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/index.js1
-rw-r--r--server/lib/auth.js20
-rw-r--r--server/lib/schemas/User.js8
3 files changed, 23 insertions, 6 deletions
diff --git a/server/index.js b/server/index.js
index d5afe6e..59dc7a5 100644
--- a/server/index.js
+++ b/server/index.js
@@ -58,6 +58,7 @@ auth.init()
// Initialize views
app.get('/', views.home);
app.get('/login', views.login);
+app.post('/login', auth.loggedIn('local'));
app.get('/logout', auth.logout);
app.get('/auth/twitter', auth.login('twitter'));
app.get('/auth/twitter/callback', auth.loggedIn('twitter'));
diff --git a/server/lib/auth.js b/server/lib/auth.js
index 22917c3..b7a2772 100644
--- a/server/lib/auth.js
+++ b/server/lib/auth.js
@@ -14,6 +14,8 @@ var auth = {
passport.serializeUser(auth.serializeUser);
passport.deserializeUser(auth.deserializeUser);
+ passport.use(auth.verifyLocalUser)
+
passport.use(new TwitterStrategy({
consumerKey: process.env.VVALLS_TWITTER_KEY || '0L5blfBIapqhpons8bCXdIoGM',
consumerSecret: process.env.VVALLS_TWITTER_SECRET || '5EKW7m7inoODqYSKbp7cadBKFp1FghBl4MBDoXNcUjKtodZfuP',
@@ -56,7 +58,7 @@ var auth = {
accept(null, false);
},
- // technically these returns the login middleware
+ // technically these return the login middleware
login: function (strategy) {
return passport.authenticate(strategy);
},
@@ -83,6 +85,19 @@ var auth = {
});
},
+ verifyLocalUser: function (username, password, done) {
+ User.findOne({ username: username }, function(err, user){
+ if (err) { return done(err); }
+ if (!user) {
+ return done(null, false, { message: 'Incorrect username.' });
+ }
+ if (! user.validPassword(password)) {
+ return done(null, false, { message: 'Incorrect password.' });
+ }
+ return done(null, user);
+ });
+ },
+
insertTwitterUser: function (accessToken, refreshToken, profile, done) {
process.nextTick(function () {
var userData = {
@@ -90,7 +105,7 @@ var auth = {
username: profile.username,
displayName: profile.displayName,
photo: profile.photos[0].value,
- links: ["https://twitter.com/" + profile.username]
+ twitterName: profile.username,
};
User.findOne({twitter_id: profile.id}, function(err, data){
@@ -114,7 +129,6 @@ var auth = {
username: profile.username || profile.displayName.toLowerCase().replace(/ /g,'-'),
displayName: profile.displayName,
photo: "http://graph.facebook.com/" + profile.id + "/picture?type=large",
- links: [profile.profileUrl]
};
User.findOne({facebook_id: profile.id}, function(err, data){
diff --git a/server/lib/schemas/User.js b/server/lib/schemas/User.js
index 9fd07e5..76a1255 100644
--- a/server/lib/schemas/User.js
+++ b/server/lib/schemas/User.js
@@ -59,12 +59,14 @@ var UserSchema = new mongoose.Schema({
type: String,
default: ""
},
- links: [
- { type: String, default: "" }
- ],
+ website: String,
+ twitterName: String,
isAdmin: { type: Boolean, default: false }
});
+UserSchema.methods.validPassword = function (pw) {
+ return this.password !== pw
+}
module.exports = exports = mongoose.model('user', UserSchema);
exports.schema = UserSchema;