Beispiel #1
0
        private ProfileBaseModel InitBaseProfileModel(ref ProfileBaseModel baseModel, User user)
        {
            if (baseModel == null)
            {
                baseModel = new ProfileBaseModel();
            }

            if (user != null)
            {
                baseModel.Email    = user.Email;
                baseModel.UserName = user.Name;
                baseModel.Locale   = user.Locale;
                baseModel.Stamp    = user.Stamp.ToBinary();
                baseModel.TimeZone = user.TimeZone;
            }

            ProfileBaseModel tmpModel = baseModel;

            baseModel.Init(GetSupportedLocales(), GetSupportedTimeZones());
            var selectedLocale = baseModel.SupportedLocales.Where(l => String.Equals(l.Value, tmpModel.Locale, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

            if (selectedLocale != null)
            {
                selectedLocale.Selected = true;
            }
            return(baseModel);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
        private ProfileBaseModel InitBaseProfileModel(ref ProfileBaseModel baseModel, User user)
        {
            if (baseModel == null)
                baseModel = new ProfileBaseModel();

            if (user != null)
            {
                baseModel.Email = user.Email;
                baseModel.UserName = user.Name;
                baseModel.Locale = user.Locale;
                baseModel.Stamp = user.Stamp.ToBinary();
                baseModel.TimeZone = user.TimeZone;
            }

            ProfileBaseModel tmpModel = baseModel;
            baseModel.Init(GetSupportedLocales(), GetSupportedTimeZones());
            var selectedLocale = baseModel.SupportedLocales.Where(l => String.Equals(l.Value, tmpModel.Locale, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
            if (selectedLocale != null)
                selectedLocale.Selected = true;
            return baseModel;
        }
        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;
        }