Advertisement
Guest User

Untitled

a guest
May 31st, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. function login(login, password){
  2. return new Promise(function(resolve, reject){
  3. ad.findUserAsync(login)
  4. .then(function(user){
  5. var context = {
  6. user: user,
  7. password: password
  8. };
  9. return resolve(context);
  10. })
  11. .catch(function(err){
  12. return reject(err);
  13. });
  14. });
  15. }
  16.  
  17. function authenticate(context){
  18. return new Promise(function(resolve, reject){
  19. ad.authenticateAsync(context.user.mail, context.password)
  20. .then(function(auth){
  21. context.auth = auth
  22. return resolve(context);
  23. })
  24. .catch(function(err){
  25. return reject(err);
  26. });
  27. })
  28. }
  29.  
  30. login(username, password)
  31. .then(authenticate)
  32. .then(function(context){
  33. if(!context.auth) return res.status(403).send({"message": "user not authenticated"});
  34. return res.status(200).send({"message": "user authenticated","data": context.user});
  35. })
  36. .catch(function(err){
  37. return next(err);
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement