Created
October 2, 2015 09:49
-
-
Save JustusAdam/7698ac41f075a41510bd 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
-- User.signup = function(user) { | |
-- return new Promise(function(resolve, reject) { | |
-- User.validate(user).then(function() { | |
-- return Bcrypt.genSalt(10); | |
-- }).then(function(salt) { | |
-- return Bcrypt.hash(user.password, salt, null); | |
-- }).then(function(saltedHashedPassword) { | |
-- return User.insertIntoDatabase(user, saltedHashedPassword); | |
-- }).then(function(userRecord) { | |
-- resolve(userRecord); | |
-- }).catch(function(error) { | |
-- reject(error); | |
-- }); | |
-- }); | |
-- }; | |
type Promise a = Either String a | |
-- in normal bind form | |
signup :: User -> Promise () | |
signup user = | |
validate >> | |
Bcrypt.genSalt 10 >>= | |
\salt -> Bcrypt.hash (user^.password) salt Nothing >>= | |
User.insertIntoDatabase user | |
-- in 'do' notation form | |
signup :: User -> Promise () | |
signup user = do | |
validate | |
salt <- Bcrypt.genSalt 10 | |
saltedHashedPassword <- Bcrypt.hash (user^.password) salt Nothing | |
userRecord <- User.insertIntoDatabase user saltedHashedPassword | |
return userRecord | |
-- mixed style (how I would write it) | |
signup :: User -> Promise () | |
signup user = do | |
validate | |
salt <- Bcrypt.genSalt 10 | |
Bcrypt.hash (user^.password) salt Nothing >>= User.insertIntoDatabase user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment