Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LoginValidation
- {
- private static UserRoles _currentUserRole;
- private string _username;
- private string _password;
- private string _errorMessage;
- private ActionOnError _onError;
- public LoginValidation(string userName, string password, ActionOnError onError)
- {
- this._username = userName;
- this._password = password;
- _onError = onError;
- }
- public LoginValidation()
- {
- }
- public delegate void ActionOnError(string errorMsg);
- public static UserRoles CurrentUserRole
- {
- get { return _currentUserRole; }
- private set { _currentUserRole = value; }
- }
- public bool ValidateUserInput(User user)
- {
- _currentUserRole = UserRoles.ANONYMOUS;//преди проверките
- bool emptyUsername = string.IsNullOrEmpty(_username);
- bool emptyPassword = string.IsNullOrEmpty(_password);
- bool isUsernameCorrect = _username.Length >= 5 ? true : false;
- bool isPasswordCorrect = _password.Length >= 5 ? true : false;
- if(emptyUsername || emptyPassword || !isUsernameCorrect || !isPasswordCorrect)
- {
- _errorMessage = "Имате грешка при въвеждането на потребителското име или паролата";
- _onError(_errorMessage);//not sure how it works tbh
- return false;
- }
- if (UserData.IsUserPassCorrect(_username, _password) != null)
- {
- user = UserData.IsUserPassCorrect(_username, _password);//not sure
- }
- else return false;
- //user.Username = UserData.TestUser.Username;
- //user.Password = UserData.TestUser.Password;
- //user.FacNumber = UserData.TestUser.FacNumber;
- //user.Role = UserData.TestUser.Role;
- _currentUserRole = (UserRoles)user.Role;
- Logger.LogActivity("Успешен Login");
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement