Last active
July 26, 2016 07:43
-
-
Save nchanged/c7b079b82e25c86bf5001b079c3875b3 to your computer and use it in GitHub Desktop.
Registration Flow (promises)
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
let pwd, email, user; | |
UserFlow.validateEmail(email) | |
.then(UserFlow.checkUserExists) // Check if user exists | |
.then(function(existingUser){ // Spitting custom exception | |
if( existingUser ){ | |
throw Error('User exists') | |
} | |
}).then(() => { | |
return UserFlow.hashPassword(pwd); // Hash password | |
}).then((hashedPwd)=>{ | |
return UserFlow.createUser(email, hashedPwd); // Actually creating user in the databse | |
}).then((newUser) => { | |
user = newUser // Saving user to later reference | |
return sendEmail(user, pwd) // Sending an email to the user | |
}).then(() => { | |
return user // Returning the user object (model) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment