Пример #1
0
        public ActionResult EditPOST(UserEditViewModel model)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageUsers, "Not authorized to manage users"))
                return new HttpUnauthorizedResult();

            var user = _userRepository.Get(model.Id);
            string previousName = user.UserName;

            if (ModelState.IsValid && !_userService.VerifyUserUnicity(model.Id, model.UserName, model.Email))
            {
                ModelState.AddModelError("UserName", "User with that username and/or email already exists.");
            }

            ///also update the Super user if this is the renamed account
            if (ModelState.IsValid && String.Equals(Services.WorkContext.CurrentSite.SuperUser, previousName, StringComparison.Ordinal))
            {
                var siteSetting = _settingService.LoadSetting<SiteSettings>(); ;
                siteSetting.SuperUser = model.UserName;
                _settingService.SaveSetting(siteSetting);
            }

            if (ModelState.IsValid)
            {
                user.Email = model.Email;
                user.UserName = model.UserName;

                user.Email = model.Email;
                user.UserName = model.UserName.ToLowerInvariant();

                Services.Notifier.Information("User information updated");
                return RedirectToAction("Index");
            }

            Services.TransactionManager.Cancel();
            return View(model);
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageUsers, "Not authorized to manage users"))
                return new HttpUnauthorizedResult();

            var user = _userRepository.Get(id);
            var model = new UserEditViewModel { Id = user.Id, Email = user.Email, UserName = user.UserName };
            return View(model);
        }