Ejemplo n.º 1
0
        public ActionResult ChangePassword(ChangePasswordUserAdminModel userModel)
        {
            string command = Request.Form["submit"].ToString();

            switch (command)
            {
            case ButtonActionName.Save:
            case ButtonActionName.SaveAndContinueEdit:
                if (ModelState.IsValid)
                {
                    try
                    {
                        User user = userService.GetUserForUpdate(userModel.Id);
                        if (user == null || (userModel.Id == 1 && WorkContext.CurrentUserId != 1))
                        {
                            ErrorNotification("Không tìm thấy tài khoản nào thỏa mãn");
                            return(RedirectToAction("Index"));
                        }
                        user.PasswordSalt = Util.RandomPasswordSalt();
                        user.Password     = Util.ComputeMD5Hash(userModel.Password + user.PasswordSalt);
                        user.Modified     = DateTime.Now;

                        userService.UpdateUser(user);

                        SuccessNotification("Đổi mật khẩu thành công");

                        if (command == ButtonActionName.SaveAndContinueEdit)
                        {
                            Title = "Chỉnh sửa thông tin tài khoản: " + user.UserName;
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                    catch (Exception e)
                    {
                        Title = "Chỉnh sửa thông tin tài khoản";
                        ErrorNotification(e);
                    }
                }

                break;

            default:
                ErrorNotification("Không rõ phương thức submit dữ liệu");
                return(RedirectToAction("Index"));
            }
            return(View(userModel));
        }
Ejemplo n.º 2
0
        //
        // GET: /Admin/Users/ChangePassword/5

        public ActionResult ChangePassword(int id)
        {
            User user = userService.GetUserForUpdate(id);

            if (user == null || (id == 1 && WorkContext.CurrentUserId != 1))
            {
                ErrorNotification("Không tìm thấy tài khoản nào thỏa mãn");
                return(RedirectToAction("Index"));
            }
            Title = "Đổi mật khẩu : " + user.UserName;

            var editModel = new ChangePasswordUserAdminModel
            {
                Id = id
            };

            ViewData["ToolbarTitle"] = Title;
            return(View(editModel));
        }