Created
May 20, 2014 18:47
-
-
Save Pajn/fa49bbd82377aafef89d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
register(Request request) { | |
var user = new User.fromJson(request.json); | |
if (!user.emailIsValid || !user.hashIsValid) { | |
return new Response('invalid data', status: Status.ERROR); | |
} | |
return db.open().then((_) { | |
DbCollection users = db.collection('Users'); | |
return users.findOne({'email': user.email}).then((dbUser) { | |
if (dbUser == null) { | |
user.strengthenHash(); | |
return users.insert(user.toJson()).then((_) { | |
db.close(); | |
return new Response('user created'); | |
}); | |
} else { | |
db.close(); | |
return new Response('email exists', status: Status.ERROR); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment