/// <summary> /// Checks wether the login info matches the given credentials /// </summary> /// <param name="loginModel"></param> public static bool Authenticate(Loginmodel loginModel) { try { // 01. Check if the user exists var _user = Get(loginModel.CredentialName); if (_user == null) { throw new UserNotFoundException(loginModel.CredentialName); } var encrypted = SecurityExtensions.Encrypt(loginModel.Password + _user.Salt); if (_user.Password == encrypted) { DAL_Users.SetAuthenticatedUser(_user.Id); return(true); } else { return(false); } } catch (Exception) { throw; } }
/// <summary> /// gets the user by its email /// </summary> /// <param name="email"></param> public static Users GetByEmailAddress(string email) { try { return(DAL_Users.GetByEmailAddress(email)); } catch (Exception) { throw; } }
/// <summary> /// returns a list of all users /// </summary> public static List <Users> GetAll() { try { return(DAL_Users.GetAll()); } catch (Exception) { throw; } }
/// <summary> /// returns the authenticated user /// </summary> public static Users GetCurrentUser() { try { return(DAL_Users.GetCurrentUser()); } catch (Exception) { throw; } }
public static bool Any() { try { return(DAL_Users.Any()); } catch (Exception) { throw; } }
/// <summary> /// Logging the current user out /// </summary> public static void Logout() { try { DAL_Users.Logout(); } catch (Exception) { throw; } }
/// <summary> /// gets the user by its username /// </summary> /// <param name="username"></param> public static Users GetByUsername(string username) { try { return(DAL_Users.GetByUsername(username)); } catch (Exception) { throw; } }
/// <summary> /// this updates the given user /// </summary> /// <param name="user"></param> /// <param name="pwd"></param> public static void Update(Users user, string pwd = null) { try { if (!string.IsNullOrWhiteSpace(pwd)) { user = ChangePassword(user, pwd); } DAL_Users.Update(user); } catch (Exception) { throw; } }
/// <summary> /// creates a new user /// </summary> /// <param name="user"></param> public static void Create(Users user) { try { if (user.Id == Guid.Empty) { user.Id = Guid.NewGuid(); } DAL_Users.Create(user); } catch (Exception) { throw; } }
public BL_Users() { DAL_Users = new DAL_Users(); }