예제 #1
0
파일: UsersBLL.cs 프로젝트: FR-MN/RGR
 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));
 }
예제 #2
0
        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"));
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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);
        }