Last active
December 26, 2015 10:08
-
-
Save zaach/7134120 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var client = new gherkin.Client('http://127.0.0.1:9000'); | |
function queryAccount(email, cb) { | |
return client.accountExists(email) | |
.done( | |
function (exists) { | |
var status = exists ? "registered" : "unregistered"; | |
cb(null, { status: status }); | |
}, | |
function (error) { | |
cb({ error: error.message }); | |
} | |
) | |
} | |
function verificationStatus(email, password, cb) { | |
client.password = password; | |
var setup = client.email ? | |
client.rawPasswordLogin() : | |
client.accountExists(email).then(client.rawPasswordLogin.bind(client, null)); | |
return setup | |
.then(client.emailStatus.bind(client, null)) | |
.done( | |
function (emailStatus) { | |
var status = emailStatus.verified ? "verified" : "unverified"; | |
cb(null, { status: status }); | |
}, | |
function (error) { | |
cb({ error: error.message }); | |
} | |
) | |
} | |
function signIn(email, password, cb) { | |
client.password = password; | |
var setup = client.email ? | |
client.rawPasswordLogin() : | |
client.accountExists(email).then(client.rawPasswordLogin.bind(client, null)); | |
return setup | |
.done( | |
function (result) { | |
cb(null, { sessionToken: result.sessionToken }); | |
}, | |
function (error) { | |
cb({ error: error.message }); | |
} | |
) | |
} | |
function signUp(email, password, cb) { | |
var token; | |
return client.rawPasswordCreate() | |
.then(client.rawPasswordLogin.bind(client)) | |
.then( | |
function (result) { | |
token = result.sessionToken; | |
} | |
) | |
.then(client.emailStatus.bind(client)) | |
.done( | |
function (emailStatus) { | |
cb({ needsConfirmation: !emailStatus.verified, sessionToken: token }); | |
}, | |
function (error) { | |
cb({ error: error.message }); | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment