forked from totaljs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.js
More file actions
32 lines (23 loc) · 839 Bytes
/
user.js
File metadata and controls
32 lines (23 loc) · 839 Bytes
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
NEWSCHEMA('User').make(function(schema) {
schema.define('email', 'Email', true);
schema.define('password', 'String(30)', true);
schema.addWorkflow('login', function(error, model, controller, callback) {
NOSQL('users').find().make(function(builder) {
builder.first();
builder.where('email', model.email);
builder.where('password', model.password);
builder.callback(function(err, response) {
if (!response) {
error.push('error-user-404');
return callback();
}
// Writes logs
NOSQL('users-logs').insert({ id: response.id, email: response.email, ip: controller.ip, date: new Date() });
// Sets cookies
controller.cookie(F.config.cookie, F.encrypt({ id: response.id, ip: controller.ip }, 'user'), '5 minutes');
// Responds
callback(SUCCESS(true));
}, error);
});
});
});