@@ -3,58 +3,53 @@ var crypto = require('crypto');
3
3
var _ = require ( 'lodash' ) ;
4
4
var Sequelize = require ( 'sequelize' ) ;
5
5
6
- module . exports = function ( db ) {
6
+ var db = require ( '../_db' ) ;
7
7
8
- db . define ( 'user' , {
9
- email : {
10
- type : Sequelize . STRING
8
+ module . exports = db . define ( 'user' , {
9
+ email : {
10
+ type : Sequelize . STRING
11
+ } ,
12
+ password : {
13
+ type : Sequelize . STRING
14
+ } ,
15
+ salt : {
16
+ type : Sequelize . STRING
17
+ } ,
18
+ twitter_id : {
19
+ type : Sequelize . STRING
20
+ } ,
21
+ facebook_id : {
22
+ type : Sequelize . STRING
23
+ } ,
24
+ google_id : {
25
+ type : Sequelize . STRING
26
+ }
27
+ } , {
28
+ instanceMethods : {
29
+ sanitize : function ( ) {
30
+ return _ . omit ( this . toJSON ( ) , [ 'password' , 'salt' ] ) ;
11
31
} ,
12
- password : {
13
- type : Sequelize . STRING
14
- } ,
15
- salt : {
16
- type : Sequelize . STRING
17
- } ,
18
- twitter_id : {
19
- type : Sequelize . STRING
20
- } ,
21
- facebook_id : {
22
- type : Sequelize . STRING
23
- } ,
24
- google_id : {
25
- type : Sequelize . STRING
32
+ correctPassword : function ( candidatePassword ) {
33
+ return this . Model . encryptPassword ( candidatePassword , this . salt ) === this . password ;
26
34
}
27
- } , {
28
- instanceMethods : {
29
- sanitize : function ( ) {
30
- return _ . omit ( this . toJSON ( ) , [ 'password' , 'salt' ] ) ;
31
- } ,
32
- correctPassword : function ( candidatePassword ) {
33
- return this . Model . encryptPassword ( candidatePassword , this . salt ) === this . password ;
34
- }
35
- } ,
36
- classMethods : {
37
- generateSalt : function ( ) {
38
- return crypto . randomBytes ( 16 ) . toString ( 'base64' ) ;
39
- } ,
40
- encryptPassword : function ( plainText , salt ) {
41
- var hash = crypto . createHash ( 'sha1' ) ;
42
- hash . update ( plainText ) ;
43
- hash . update ( salt ) ;
44
- return hash . digest ( 'hex' ) ;
45
- }
35
+ } ,
36
+ classMethods : {
37
+ generateSalt : function ( ) {
38
+ return crypto . randomBytes ( 16 ) . toString ( 'base64' ) ;
46
39
} ,
47
- hooks : {
48
- beforeValidate : function ( user ) {
49
- if ( user . changed ( 'password' ) ) {
50
- user . salt = user . Model . generateSalt ( ) ;
51
- user . password = user . Model . encryptPassword ( user . password , user . salt ) ;
52
- }
40
+ encryptPassword : function ( plainText , salt ) {
41
+ var hash = crypto . createHash ( 'sha1' ) ;
42
+ hash . update ( plainText ) ;
43
+ hash . update ( salt ) ;
44
+ return hash . digest ( 'hex' ) ;
45
+ }
46
+ } ,
47
+ hooks : {
48
+ beforeValidate : function ( user ) {
49
+ if ( user . changed ( 'password' ) ) {
50
+ user . salt = user . Model . generateSalt ( ) ;
51
+ user . password = user . Model . encryptPassword ( user . password , user . salt ) ;
53
52
}
54
53
}
55
- } ) ;
56
-
57
-
58
-
59
- } ;
60
-
54
+ }
55
+ } ) ;
0 commit comments