Ejemplo n.º 1
0
        public ActionResult ChangePassword(string userName, Models.ChangePasswordModel model)
        {
            try
            {
                if ((!User.Identity.IsAuthenticated) || (userName != User.Identity.Name))
                {
                    throw new RestfulModels.NoAccessException();
                }

                if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                {
                    Response.StatusCode = 200;
                    return(null);
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (RestfulModels.NoAccessException)
            {
                Response.StatusCode = 401;
                return(null);
            }
            catch
            {
                Response.StatusCode = 404;
                return(null);
            }
        }
Ejemplo n.º 2
0
 public ActionResult ChangePassword(Models.ChangePasswordModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var  userDAL   = new UserDAL();
             bool succeeded = userDAL.ChangePassword(CurrentUser.UserName, model.OldPassword, model.NewPassword);
             if (succeeded)
             {
                 return(JavaScript(@"noticeChangePassWord(true, 'Change password succesfully.');"));
             }
             else
             {
                 ModelState.AddModelError("OldPassword", "OldPassword is invailid");
             }
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("NewPassword", "Change password error");
         }
     }
     // If we got this far, something failed, redisplay form
     return(PartialView("_ChangePass", model));
 }
Ejemplo n.º 3
0
 public ActionResult SetPassword(Models.ChangePasswordModel model, string username)
 {
     if (model.NewPassword == model.ConfirmPassword)
     {
         try
         {
             var  userDAL   = new UserDAL();
             bool succeeded = userDAL.ChangePassword(username, model.NewPassword);
             if (succeeded)
             {
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ModelState.AddModelError("NewPassword", "NewPassword is invailid");
             }
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("NewPassword", "Set password error");
         }
     }
     // If we got this far, something failed, redisplay form
     return(RedirectToAction("SetPassword", new { username = username }));
 }
Ejemplo n.º 4
0
        public ActionResult ChangePassword(Models.ChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (!CheckLogon())
            {
                return(Redirect((int)Errors.NOT_LOGIN));
            }

            // Lấy thông tin tài khoản.
            User user = userService.GetById(int.Parse(CookieHelper.Get(AdminConfigs.COOKIES_USER_ID)));

            // Kiểm tra thông tin mật khẩu cũ
            if (user.Password != EncryptionHelper.Encrypt(model.OldPassword))
            {
                // Mật khẩu không đúng.
                ModelState.AddModelError(string.Empty, "Mật khẩu cũ không chính xác");
                return(View());
            }

            user.Password = EncryptionHelper.Encrypt(model.NewPassword);
            userService.Update(user);
            TempData[AdminConfigs.TEMP_MESSAGE] = "Bạn đã đổi mật khẩu thành công!";

            return(RedirectToAction("PersonalInfo", "User"));
        }
Ejemplo n.º 5
0
        public ActionResult SetPassword(Guid id)
        {
            var model = new Models.ChangePasswordModel();

            // todo: Verify that user has setpassword permission
            model.UserID = id;
            return(View(model));
        }
Ejemplo n.º 6
0
        public ActionResult SetPassword(Models.ChangePasswordModel command)
        {
            var service = new Commanding.SimpleTwitterCommandServiceClient();

            service.SetUserPassword(new Commands.SetUserPasswordCommand()
            {
                UserID   = command.UserID,
                Password = command.NewPassword
            });

            return(RedirectToAction("Details", new { id = command.UserID }));
        }
Ejemplo n.º 7
0
        public ActionResult ChangePassword(Models.ChangePasswordModel ChangedPass)
        {
            if (ModelState.IsValid)
            {
                if (Logic.Auth(ChangedPass.UserName, ChangedPass.OldPass))
                {
                    Logic.ChangePasswordForUser(ChangedPass.UserName, ChangedPass.NewPass);
                    return(Redirect("~/Account/ProfilePage?Name=" + ChangedPass.UserName));
                }
                ModelState.AddModelError("OldPass", "Неверный пароль.");
            }

            return(View(ChangedPass));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> ChangePassword([FromBody] Models.ChangePasswordModel model)
        {
            // get the user to be updated
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            // now change the password
            var result = await _userManager.ChangePasswordAsync(user, model.OldPassword, model.NewPassword);

            if (!result.Succeeded)
            {
                return(BadRequest(result.Errors.First().Description));
            }

            return(Ok());
        }
Ejemplo n.º 9
0
        public ActionResult ChangePassword(Models.ChangePasswordModel model, string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            try
            {
                int userID = (User.Identity as UserProfileIdentity).GetUserId();
                var result = UserManager.ChangePasswordAsync(userID, model.OldPassword, model.NewPassword);
                if (result.Result.Succeeded)
                {
                    var user = UserManager.FindByIdAsync(userID);
                    if (user.Result != null)
                    {
                        SignInManager.SignInAsync(user.Result, isPersistent: false, rememberBrowser: false);
                    }
                    ShowSuccessSnackbar("تم تغيير كلمة المرور بنجاح");
                    if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    return(RedirectToAction("index", "Home"));
                }
                else if (result.Result.Errors.Contains("Incorrect password."))
                {
                    ShowDangerSnackbar("كلمة المرور غير صحيحة.");
                }
                else
                {
                    ShowDangerSnackbar("عفوأ. حدث خطأ أثناء تعديل كلمة المرور. الرجاء المحاولة لاحقاً.");
                }
            }
            catch
            {
                ShowDangerSnackbar("عفوأ. حدث خطأ أثناء تعديل كلمة المرور. الرجاء المحاولة لاحقاً.");
            }
            return(View(model));
        }
Ejemplo n.º 10
0
 public ActionResult ChangePassword(Models.ChangePasswordModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.OldPassword.Equals(model.NewPassword))
         {
             ModelState.AddModelError("NewPassword", "Mật khẩu mới phải khác mật khẩu cũ!");
         }
         else
         {
             try
             {
                 var  userDAL   = new UserDAL();
                 bool succeeded = userDAL.ChangePassword(CurrentUser.UserName, model.OldPassword, model.NewPassword);
                 if (succeeded)
                 {
                     return(JavaScript(@"noticeChangePassWord(true, 'Đổi mật khẩu thành công.');"));
                 }
                 else
                 {
                     ModelState.AddModelError("OldPassword", "Mật khẩu hiện tại không đúng.");
                 }
             }
             catch (ArgumentException)
             {
                 ModelState.AddModelError("NewPassword", "Mật khẩu yêu cầu tối thiểu phải 6 kí tự.");
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError("NewPassword", "Mật khẩu yêu cầu tối thiểu phải 6 kí tự.");
             }
         }
     }
     // If we got this far, something failed, redisplay form
     return(PartialView("_ChangePass", model));
 }
Ejemplo n.º 11
0
 public ActionResult SetPassword(Guid id)
 {
     var model = new Models.ChangePasswordModel();
     // todo: Verify that user has setpassword permission
     model.UserID = id;
     return View(model);
 }
Ejemplo n.º 12
0
 public JsonResult SaveNewPassword(Models.ChangePasswordModel model)
 {
     return(Json(DataAccess.Account.SetNewPassword(model.AccountID, model.NewPassword, model.OldPassword, model.Origin.ToLower().Equals("/account/profile"))));
 }
 public ChangePasswordViewModel(Models.ChangePasswordModel result, INavigation navigation)
 {
     Model       = result;
     Navigation  = navigation;
     SendCommand = new Command(SendCommandAction);
 }
 public ChangePasswordView(Models.ChangePasswordModel result)
 {
     InitializeComponent();
     BindingContext = new ChangePasswordViewModel(result, Navigation);
 }
        public ActionResult ChangePasword(Models.ChangePasswordModel ch)
        {
            string email = ch.Email;

            //OBTAINING USER ID AND DETAILS
            var user = new DataTable();

            using (var sqlCon = new SqlConnection(connectString))
            {
                sqlCon.Open();
                var query = "Select * from UserDetails where Email='" + email + "';";
                var sqlDa = new SqlDataAdapter(query, sqlCon);
                sqlDa.Fill(user);
            }
            int    id  = (int)user.Rows[0][0];
            string old = user.Rows[0][3].ToString();

            //MATCHING OLD PASSWORD WITH INPUT
            if (ch.OldPassword.Equals(old))
            {
                //UPDATING PASSWORD IF PASSWORDS MATCH
                if (ch.NewPassword.Equals(ch.ConfirmNewPass))
                {
                    using (SqlConnection sqlConnection = new SqlConnection(connectString))
                    {
                        sqlConnection.Open();
                        string query = "Update Userdetails set pass=@newpass where userId=" + id;

                        SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
                        sqlCommand.Parameters.AddWithValue("@newpass", ch.NewPassword);

                        sqlCommand.ExecuteNonQuery();
                    }
                }
                else
                {
                    //new pass and confirm pass doesnt match
                    TempData["msg"] = "<script>alert('Your new password did not match the confirmation password')</script>";
                    ChangePasswordModel chViewModel1 = new ChangePasswordModel();
                    chViewModel1.Email = email;
                    return(View(chViewModel1));
                }
            }
            else
            {
                //old password doesnt match
                TempData["msg"] = "<script>alert('Your Old Password is incorrect. Please try again.')</script>";
                ChangePasswordModel chViewModel1 = new ChangePasswordModel();
                chViewModel1.Email = email;
                return(View(chViewModel1));
            }
            byte bloggerStat = (byte)user.Rows[0][4];

            TempData["msg"] = "<script>alert('You have successfully changed your password')</script>";
            //NORMAL USER REDIRECT TO HOMEPAGE
            if (bloggerStat == 0)
            {
                return(RedirectToAction("Index", "User", new { email = email }));
            }
            //USER-WHO-APPLIED-TO-BE-BLOGGER REDIRECT TO HOMEPAGE
            else if (bloggerStat == 1)
            {
                return(RedirectToAction("Index1", "User", new { email = email }));
            }
            //BLOGGER REDIRECT TO HOMEPAGE
            else
            {
                return(RedirectToAction("Index", "Blogger", new { email = email }));
            }
        }