Created
May 5, 2015 00:56
-
-
Save cj3kim/e9512711a83a57379b36 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
login: Promise.method(function (email, password) { | |
if (!email || !password) throw new Error("Email and password are both required."); | |
var storage = { user: null }; | |
var fetchPromise = new this({ email: email.toLowerCase().trim() }) | |
.bind(storage) | |
.fetch({ require: true }) | |
.then(function (user) { | |
this.user = user; | |
return bcrypt.compareAsync(password, user.get('password')) | |
}) | |
.then(function (samePassword) { | |
if (!samePassword) throw new Error("Invalid email or password"); | |
return Promise.resolve(this.user); | |
}) | |
return fetchPromise; | |
}), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment