コード例 #1
0
ファイル: ProfileController.cs プロジェクト: ttcp112/CSC
        public ActionResult ChangePassword(EmployeeDetailModels model)
        {
            listStorePropertiesReject = new List <string>();
            listStorePropertiesReject.Add("ZipCode");
            listStorePropertiesReject.Add("Country");
            listStorePropertiesReject.Add("Phone");
            PropertyReject();

            string _newPassword = "", _oldPassword = "", _comfirmPassword = "";

            try
            {
                _newPassword     = model.NewPassword;
                _oldPassword     = model.OldPassword;
                _comfirmPassword = model.ConfirmPassword;
                if (string.IsNullOrEmpty(model.OldPassword))
                {
                    ModelState.AddModelError("OldPassword", "Current Password field is required");
                }

                if (string.IsNullOrEmpty(model.NewPassword))
                {
                    ModelState.AddModelError("NewPassword", "New Password field is required");
                }

                if (string.IsNullOrEmpty(model.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", "Confirm New Password field is required");
                }

                if (!model.NewPassword.Equals(model.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", "Confirm New Password and new password incorrect");
                }

                if (!ModelState.IsValid)
                {
                    model                 = GetDetail(model.ID);
                    model.OldPassword     = _oldPassword;
                    model.NewPassword     = _newPassword;
                    model.ConfirmPassword = _comfirmPassword;
                    Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }

                string msg    = "";
                string mec    = CurrentUser.OrganizationId;
                string useid  = CurrentUser.UserId;
                var    result = _factory.ChangePassword(model, ref msg, mec, useid);
                if (result)
                {
                    return(RedirectToAction("Logout", "Home", new { area = "" }));
                }
                else
                {
                    ModelState.AddModelError("ConfirmPassword", msg);
                    model                 = GetDetail(model.ID);
                    model.OldPassword     = _oldPassword;
                    model.NewPassword     = _newPassword;
                    model.ConfirmPassword = _comfirmPassword;
                    /*===*/
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                NSLog.Logger.Error("Employee_Change Password Error: ", ex);
                ModelState.AddModelError("ConfirmPassword", ex.Message);
                model                 = GetDetail(model.ID);
                model.OldPassword     = _oldPassword;
                model.NewPassword     = _newPassword;
                model.ConfirmPassword = _comfirmPassword;
                Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                return(View(model));
            }
        }
コード例 #2
0
ファイル: ProfileController.cs プロジェクト: ttcp112/FJ
        public ActionResult ChangePassword(EmployeeModels model)
        {
            string _newPassword = "", _oldPassword = "", _comfirmPassword = "";

            try
            {
                _newPassword     = model.NewPassword;
                _oldPassword     = model.OldPassword;
                _comfirmPassword = model.ConfirmPassword;
                if (string.IsNullOrEmpty(model.OldPassword))
                {
                    ModelState.AddModelError("OldPassword", CurrentUser.GetLanguageTextFromKey("Current Password field is required"));
                }

                if (string.IsNullOrEmpty(model.NewPassword))
                {
                    ModelState.AddModelError("NewPassword", CurrentUser.GetLanguageTextFromKey("New Password field is required"));
                }

                if (string.IsNullOrEmpty(model.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", CurrentUser.GetLanguageTextFromKey("Confirm New Password field is required"));
                }

                if (!model.NewPassword.Equals(model.ConfirmPassword))
                {
                    ModelState.AddModelError("ConfirmPassword", CurrentUser.GetLanguageTextFromKey("Confirm New Password and new password incorrect"));
                }

                if (!ModelState.IsValid)
                {
                    model                 = GetDetail(model.ID);
                    model.OldPassword     = _oldPassword;
                    model.NewPassword     = _newPassword;
                    model.ConfirmPassword = _comfirmPassword;
                    Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }

                string msg    = "";
                string mec    = CurrentUser.ListOrganizationId[0];
                var    result = _factory.ChangePassword(model, ref msg, mec);
                if (result)
                {
                    return(RedirectToAction("Logout", "Home", new { area = "" }));
                }
                else
                {
                    ModelState.AddModelError("ConfirmPassword", msg);
                    model                 = GetDetail(model.ID);
                    model.OldPassword     = _oldPassword;
                    model.NewPassword     = _newPassword;
                    model.ConfirmPassword = _comfirmPassword;
                    /*===*/
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Employee_Change Password: "******"ConfirmPassword", CurrentUser.GetLanguageTextFromKey(ex.Message));
                model                 = GetDetail(model.ID);
                model.OldPassword     = _oldPassword;
                model.NewPassword     = _newPassword;
                model.ConfirmPassword = _comfirmPassword;
                Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                return(View(model));
            }
        }