示例#1
0
 private ProfilePasswordModel InitProfilePasswordModel(ref ProfilePasswordModel passwdModel, User user)
 {
     if (passwdModel == null)
     {
         passwdModel = new ProfilePasswordModel();
     }
     if (user != null)
     {
         passwdModel.Stamp = user.Stamp.ToBinary();
     }
     passwdModel.Init(_membershipService.MinPasswordLength);
     return(passwdModel);
 }
示例#2
0
        public ActionResult ChangePassword(ProfilePasswordModel passwordModel)
        {
            Identity identity = User.Identity;

            if (ModelState.IsValid)
            {
                try
                {
                    _membershipService.ChangePassword(identity.UserId, passwordModel.NewPassword, passwordModel.OldPassword, DateTime.FromBinary(passwordModel.Stamp));
                    TempData.AddRequestSuccessMessage(SuccessMessagesResources.PasswordChangedInfo);
                    return(RedirectToAction("Edit"));
                }
                catch (StaleUserException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountStalled);
                }
                catch (UserNotExistsException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountNotFound);
                }
                catch (PasswordsMismatchException)
                {
                    ModelState.AddModelError("profile", ValidationResources.OldPasswordsMismatchError);
                }
                catch (InvalidPasswordException)
                {
                    ModelState.AddModelError("NewPassword", ValidationResources.RegInvalidPassword);
                }
            }

            //smth went wrong
            ProfileBaseModel baseModel = null;
            ProfileModel     model     = new ProfileModel
            {
                BaseModel     = InitBaseProfileModel(ref baseModel, _userService.Load(identity.UserId)),
                PasswordModel = InitProfilePasswordModel(ref passwordModel, null)
            };
            var resultAction = Condition()
                               .DoIfNotAjax(() => View("Edit", model))
                               .DoIfAjax(() => Json(new AjaxResult
            {
                MainPanelHtml = this.RenderViewToString("~/Views/Account/Controls/ProfileControl.ascx", model)
            }, JsonRequestBehavior.AllowGet));

            return(resultAction);
        }
示例#3
0
        public ActionResult Edit(ProfileBaseModel baseModel)
        {
            if (ModelState.IsValid)
            {
                Identity identity = User.Identity;

                try
                {
                    _membershipService.UpdateUser(identity.UserId, baseModel.UserName, baseModel.Locale, baseModel.TimeZone, DateTime.FromBinary(baseModel.Stamp), identity);
                    TempData.AddRequestSuccessMessage(SuccessMessagesResources.ProfileUpdateSuccessMessage);
                    return(RedirectToAction("Edit"));
                }
                catch (StaleUserException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountStalled);
                }
                catch (InvalidUserNameException)
                {
                    ModelState.AddModelError("UserName", ValidationResources.RegInvalidUserName);
                }
                catch (UserNotExistsException)
                {
                    ModelState.AddModelError("profile", ValidationResources.AccountNotFound);
                }
            }

            ProfilePasswordModel passwdModel = null;

            baseModel = InitBaseProfileModel(ref baseModel, null);
            ProfileModel model = new ProfileModel
            {
                BaseModel     = baseModel,
                PasswordModel = InitProfilePasswordModel(ref passwdModel, null)
            };
            var resultAction = Condition()
                               .DoIfNotAjax(() => View(model))
                               .DoIfAjax(() => Json(new AjaxResult
            {
                MainPanelHtml = this.RenderViewToString("~/Views/Account/Controls/ProfileControl.ascx", model)
            }, JsonRequestBehavior.AllowGet));

            return(resultAction);
        }
示例#4
0
        public ActionResult Edit()
        {
#warning return nav bar page
            ProfileModel model        = null;
            var          resultAction = Condition()
                                        .DoIfNotAjax(() => View(model))
                                        .DoIfAjax(() => Json(new AjaxResult
            {
                MainPanelHtml = this.RenderViewToString("~/Views/Account/Controls/ProfileControl.ascx", model)
            }, JsonRequestBehavior.AllowGet));

            User user = _userService.Load(User.Identity.UserId);

            ProfileBaseModel     baseModel   = null;
            ProfilePasswordModel passwdModel = null;
            model = new ProfileModel()
            {
                BaseModel     = InitBaseProfileModel(ref baseModel, user),
                PasswordModel = InitProfilePasswordModel(ref passwdModel, user)
            };
            return(resultAction);
        }