-
Notifications
You must be signed in to change notification settings - Fork 12
/
auth.js
61 lines (53 loc) · 1.7 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Everyauth config for the app
var mongoose = require('mongoose')
, mongoose_auth = require('mongoose-auth')
, Schema = mongoose.Schema
;
var CommentSchema = new Schema({
body : String
, date : Date
});
var Comment = mongoose.model('Comment', CommentSchema);
exports.Comment = Comment;
var user_schema = new Schema();
user_schema.plugin(mongoose_auth, {
everymodule: {
everyauth: {
User: function () {
return user;
}
}
}
, password: {
loginWith: 'email'
, everyauth: {
getLoginPath: '/login'
, postLoginPath: '/login'
, loginView: 'login.jade'
, getRegisterPath: '/register'
, postRegisterPath: '/register'
, registerView: 'register.jade'
, loginSuccessRedirect: '/'
, registerSuccessRedirect: '/'
, loginLocals: {product:'Poang', page:'Sample node.js / express / everyauth / mongodb app for Strider and Heroku'}
, registerLocals: {product:'Strider', page:'Sample node.js / express / everyauth / mongodb app for Strider and Heroku', code:''}
, registerUser: function (newUserAttributes) {
var promise = this.Promise();
this.User()().create(newUserAttributes, function (err, createdUser) {
if (err) {
console.log(err);
if (/duplicate key/.test(err)) {
return promise.fulfill(['Someone has already claimed that login']);
}
return promise.fail(err);
}
promise.fulfill(createdUser);
});
return promise;
}
}
}
});
mongoose.model('user', user_schema);
var user = mongoose.model('user');
exports.user = user;