Guest User

Untitled

a guest
Oct 18th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. Accounts.validateLoginAttempt(function(info){
  2. var user = info.user;
  3. var failAttemp = user.profile.loginFaileAttempt;
  4. if(failAttemp == 3){
  5. console.log('you need to contact the admin!')
  6. return false;
  7. }else{
  8.  
  9. if(Meteor.Error == 'Incorrect password '){
  10. // incremnt the fail attempts
  11. failAttemp++;
  12. console.log(failAttemp);
  13. }
  14. }
  15.  
  16. return true;
  17. // success login set to 0
  18. failAttemp = 0;
  19.  
  20. });
  21.  
  22. Accounts.validateLoginAttempt(function(info){
  23. var user = info.user;
  24. if (!user)
  25. return false;
  26.  
  27. var failAttempt = 0;
  28. if (user.profile)
  29. failAttempt = user.profile.loginFaileAttempt;
  30.  
  31. var loginAllowed = false;
  32. if(info.error && info.error.error == 403){
  33. if(failAttempt >= 3) {
  34. console.log('you need to contact the admin!');
  35. throw new Meteor.Error(403, 'you need to contact the admin!');
  36. }
  37. // increment the fail attempts
  38. failAttempt++;
  39. console.log(failAttempt);
  40. loginAllowed = false;
  41. } else {
  42. // success login set to 0
  43. failAttempt = 0;
  44. loginAllowed = true;
  45. }
  46.  
  47. Meteor.users.update({_id: user._id}, {$set: {'profile.loginFaileAttempt': failAttempt}});
  48.  
  49. return loginAllowed;
  50. });
Add Comment
Please, Sign In to add comment