예제 #1
0
        public IActionResult OnPost()
        {
            var settings = _settingsManager.GetSettings <SecuritySettings>();

            Differ.Init(settings);
            if (Differ.IsDifference(Input))
            {
                _settingsManager.SaveSettings(Input);
                EventLogger.LogUser($"更新了用户配置信息:{Differ}");
            }

            return(RedirectToSuccessPage("你已经成功更新了配置!"));
        }
예제 #2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByIdAsync(Input.UserId);

                if (user == null)
                {
                    return(Error("未找到任何关联用户!"));
                }
                Differ.Init(user);
                if (user.UserName != Input.UserName)
                {
                    user.UserName = Input.UserName;
                    var duplicated = await _userManager.IsDuplicatedAsync(user);

                    if (!duplicated.Succeeded)
                    {
                        return(Error(duplicated.ToErrorString()));
                    }
                }

                if (user.Email != Input.Email)
                {
                    user.Email           = Input.Email;
                    user.NormalizedEmail = _userManager.NormalizeKey(Input.Email);
                    user.EmailConfirmed  = !string.IsNullOrEmpty(Input.Email) && !Settings.RequiredEmailConfirmed;
                }

                if (user.PhoneNumber != Input.PhoneNumber)
                {
                    user.PhoneNumber          = Input.PhoneNumber;
                    user.PhoneNumberConfirmed = !string.IsNullOrEmpty(Input.PhoneNumber) && !Settings.RequiredPhoneNumberConfirmed;
                }

                if (Differ.IsDifference(user))
                {
                    var result = await _userManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        EventLogger.LogUser($"更新了用户“{user.UserName}”的信息:{Differ}");
                        return(Success("你已经成功更新了用户信息!"));
                    }
                    return(Error(result.ToErrorString()));
                }
                return(Success("你已经成功更新了用户信息!"));
            }
            return(Error());
        }