public bool UpdateUser(UserDTO user) { if (user == null) { throw new ArgumentNullException("user data is null"); } else if (!IsUserCorrect(user)) { throw new Exception("IncorrectData"); } try { usersDAL.GetUserById(user.Id); } catch { throw new ArgumentNullException("such user does not exist"); } foreach (var userData in GetAllUsers()) { if (user.Email == userData.Email && user.Nickname == userData.Nickname && user.Id != userData.Id) { return(false); } } return(usersDAL.UpdateUser(user)); }
public IActionResult ChangeMemberRole(ChangeMemberRoleViewModel vm) { if (authProvider.IsLoggedIn) { User currentUser = authProvider.GetCurrentUser(); if (currentUser.FamilyRole == "Leader") { User userToUpdate = usersDAL.GetUser(vm.userToChange.Id); if (userToUpdate.FamilyRole != vm.userToChange.FamilyRole) { FamilyRoleEmail emailModel = new FamilyRoleEmail() { PreviousRole = userToUpdate.FamilyRole, UserWhoMadeChange = currentUser, Family = familyDAL.GetFamily(userToUpdate.FamilyId) }; userToUpdate.FamilyRole = vm.userToChange.FamilyRole; emailModel.User = userToUpdate; if (usersDAL.UpdateUser(userToUpdate)) { emailProvider.FamilyRoleChanged(emailModel); } } return(RedirectToAction("Index")); } else { return(View("NotAllowed")); } } else { return(View("Login", "Account")); } }
public bool ChangePassword(string existingPassword, string newPassword) { var hashProvider = new HashProvider(); var user = GetCurrentUser(); if (user != null && hashProvider.VerifyPasswordMatch(user.Password, existingPassword, user.Salt)) { var newHash = hashProvider.HashPassword(newPassword); user.Password = newHash.Password; user.Salt = newHash.Salt; usersDAL.UpdateUser(user); return(true); } return(false); }
/// <summary> /// Changes the current user's password. /// </summary> /// <param name="existingPassword"></param> /// <param name="newPassword"></param> /// <returns></returns> public bool ChangePassword(string existingPassword, string newPassword) { var hashProvider = new HashProvider(); var user = GetCurrentUser(); // Confirm existing password match if (user != null && hashProvider.VerifyPasswordMatch(user.Password, existingPassword, user.Salt)) { // Hash new password var newHash = hashProvider.HashPassword(newPassword); user.Password = newHash.Password; user.Salt = newHash.Salt; // Save into the db userDAL.UpdateUser(user); return(true); } return(false); }