Advertisement
didito33

LoginValidations

Mar 11th, 2023
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. public class LoginValidation
  2. {
  3. private static UserRoles _currentUserRole;
  4. private string _username;
  5. private string _password;
  6. private string _errorMessage;
  7. private ActionOnError _onError;
  8. public LoginValidation(string userName, string password, ActionOnError onError)
  9. {
  10. this._username = userName;
  11. this._password = password;
  12. _onError = onError;
  13. }
  14. public LoginValidation()
  15. {
  16.  
  17. }
  18.  
  19. public delegate void ActionOnError(string errorMsg);
  20. public static UserRoles CurrentUserRole
  21. {
  22. get { return _currentUserRole; }
  23. private set { _currentUserRole = value; }
  24. }
  25.  
  26. public bool ValidateUserInput(User user)
  27. {
  28. _currentUserRole = UserRoles.ANONYMOUS;//преди проверките
  29.  
  30. bool emptyUsername = string.IsNullOrEmpty(_username);
  31. bool emptyPassword = string.IsNullOrEmpty(_password);
  32. bool isUsernameCorrect = _username.Length >= 5 ? true : false;
  33. bool isPasswordCorrect = _password.Length >= 5 ? true : false;
  34.  
  35. if(emptyUsername || emptyPassword || !isUsernameCorrect || !isPasswordCorrect)
  36. {
  37. _errorMessage = "Имате грешка при въвеждането на потребителското име или паролата";
  38. _onError(_errorMessage);//not sure how it works tbh
  39. return false;
  40. }
  41.  
  42. if (UserData.IsUserPassCorrect(_username, _password) != null)
  43. {
  44. user = UserData.IsUserPassCorrect(_username, _password);//not sure
  45. }
  46. else return false;
  47.  
  48. //user.Username = UserData.TestUser.Username;
  49. //user.Password = UserData.TestUser.Password;
  50. //user.FacNumber = UserData.TestUser.FacNumber;
  51. //user.Role = UserData.TestUser.Role;
  52.  
  53. _currentUserRole = (UserRoles)user.Role;
  54. Logger.LogActivity("Успешен Login");
  55. return true;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement