@@ -27,11 +27,15 @@ export function findUserByUsername(username, cb) {
27
27
const EMAIL_VERIFY_TOKEN_EXPIRY_TIME = Date . now ( ) + ( 3600000 * 24 ) ; // 24 hours
28
28
29
29
export function createUser ( req , res , next ) {
30
+ let { username, email } = req . body ;
31
+ const { password } = req . body ;
32
+ username = username . toLowerCase ( ) ;
33
+ email = email . toLowerCase ( ) ;
30
34
random ( ( tokenError , token ) => {
31
35
const user = new User ( {
32
- username : req . body . username ,
33
- email : req . body . email ,
34
- password : req . body . password ,
36
+ username,
37
+ email,
38
+ password,
35
39
verified : User . EmailConfirmation . Sent ,
36
40
verifiedToken : token ,
37
41
verifiedTokenExpires : EMAIL_VERIFY_TOKEN_EXPIRY_TIME ,
@@ -40,8 +44,8 @@ export function createUser(req, res, next) {
40
44
User . findOne (
41
45
{
42
46
$or : [
43
- { email : req . body . email } ,
44
- { username : req . body . username }
47
+ { email } ,
48
+ { username }
45
49
]
46
50
} ,
47
51
( err , existingUser ) => {
@@ -51,7 +55,7 @@ export function createUser(req, res, next) {
51
55
}
52
56
53
57
if ( existingUser ) {
54
- const fieldInUse = existingUser . email === req . body . email ? 'Email' : 'Username' ;
58
+ const fieldInUse = existingUser . email === email ? 'Email' : 'Username' ;
55
59
res . status ( 422 ) . send ( { error : `${ fieldInUse } is in use` } ) ;
56
60
return ;
57
61
}
@@ -77,8 +81,8 @@ export function createUser(req, res, next) {
77
81
78
82
mail . send ( mailOptions , ( mailErr , result ) => { // eslint-disable-line no-unused-vars
79
83
res . json ( {
80
- email : req . user . email ,
81
- username : req . user . username ,
84
+ email,
85
+ username,
82
86
preferences : req . user . preferences ,
83
87
verified : req . user . verified ,
84
88
id : req . user . _id
0 commit comments