예제 #1
0
        public ActionResult MySettings(MySettingsModel model)
        {
            var user = PermissionContext.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);
                PermissionContext.LanguagePreferenceSetting.Value = 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 }));
        }
예제 #2
0
        public ActionResult MySettings(MySettingsModel model)
        {
            var user = PermissionContext.LoggedUser;

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

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

            UpdateUserSettingsContract contract;

            try {
                contract = model.ToContract();
            } catch (InvalidFormException x) {
                AddFormSubmissionError(x.Message);
                return(View(model));
            }

            UserWithPermissionsContract newUser;

            try {
                newUser = Data.UpdateUserSettings(contract);
                LoginManager.SetLoggedUser(newUser);
                PermissionContext.LanguagePreferenceSetting.Value = 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));
            } catch (InvalidUserNameException) {
                ModelState.AddModelError("Username", "Username is invalid. Username may contain alphanumeric characters and underscores.");
                return(View(model));
            } catch (UserNameAlreadyExistsException) {
                ModelState.AddModelError("Username", "Username is already in use.");
                return(View(model));
            } catch (UserNameTooSoonException) {
                ModelState.AddModelError("Username", "Username may only be changed once per year. If necessary, contact a staff member.");
                return(View(model));
            }

            // Updating username currently requires signing in again
            if (newUser.Name != user.Name)
            {
                FormsAuthentication.SignOut();
            }

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

            return(RedirectToAction("Profile", new { id = newUser.Name }));
        }
예제 #3
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 }));
        }