示例#1
0
        public ActionResult MySettings(MySettingsModel model, [FromJson] IList<WebLinkDisplay> webLinksJson)
        {
            var user = LoginManager.LoggedUser;

            if (user.Id != model.Id)
                return new HttpStatusCodeResult(403);

            model.WebLinks = webLinksJson;

            if (!ModelState.IsValid)
                return View(new MySettingsModel(GetUserForMySettings()));

            if (!string.IsNullOrEmpty(model.Email)) {
                try {
                    new MailAddress(model.Email);
                } catch (FormatException) {
                    ModelState.AddModelError("Email", ViewRes.User.MySettingsStrings.InvalidEmail);
                    return View(model);
                }
            }

            try {
                var newUser = Service.UpdateUserSettings(model.ToContract());
                LoginManager.SetLoggedUser(newUser);
            } catch (InvalidPasswordException x) {
                ModelState.AddModelError("OldPass", x.Message);
                return View(model);
            }

            TempData.SetSuccessMessage(ViewRes.User.MySettingsStrings.SettingsUpdated);

            return RedirectToAction("Profile", new { id = user.Name });
        }
示例#2
0
        public ActionResult MySettings(MySettingsModel model)
        {
            var user = LoginManager.LoggedUser;

            if (user == null || user.Id != model.Id)
                return new HttpStatusCodeResult(403);

            if (!ModelState.IsValid)
                return View(new MySettingsModel(GetUserForMySettings()));

            try {
                var newUser = Data.UpdateUserSettings(model.ToContract());
                LoginManager.SetLoggedUser(newUser);
                LoginManager.SetLanguagePreferenceCookie(model.DefaultLanguageSelection);
            } catch (InvalidPasswordException x) {
                ModelState.AddModelError("OldPass", x.Message);
                return View(model);
            } catch (UserEmailAlreadyExistsException) {
                ModelState.AddModelError("Email", ViewRes.User.MySettingsStrings.EmailTaken);
                return View(model);
            } catch (InvalidEmailFormatException) {
                ModelState.AddModelError("Email", ViewRes.User.MySettingsStrings.InvalidEmail);
                return View(model);
            }

            TempData.SetSuccessMessage(ViewRes.User.MySettingsStrings.SettingsUpdated);

            return RedirectToAction("Profile", new { id = user.Name });
        }