Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function login(login, password){
- return new Promise(function(resolve, reject){
- ad.findUserAsync(login)
- .then(function(user){
- var context = {
- user: user,
- password: password
- };
- return resolve(context);
- })
- .catch(function(err){
- return reject(err);
- });
- });
- }
- function authenticate(context){
- return new Promise(function(resolve, reject){
- ad.authenticateAsync(context.user.mail, context.password)
- .then(function(auth){
- context.auth = auth
- return resolve(context);
- })
- .catch(function(err){
- return reject(err);
- });
- })
- }
- login(username, password)
- .then(authenticate)
- .then(function(context){
- if(!context.auth) return res.status(403).send({"message": "user not authenticated"});
- return res.status(200).send({"message": "user authenticated","data": context.user});
- })
- .catch(function(err){
- return next(err);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement