示例#1
0
        private async Task <ProfileVM> GetProfileVM(IUser user, ChangeProfileModel model = null, string errorMessage = null, string successMessage = null)
        {
            var externalProviders = await signInManager.GetExternalProvidersAsync();

            var result = new ProfileVM
            {
                Id                = user.Id,
                Email             = user.Email,
                ErrorMessage      = errorMessage,
                ExternalLogins    = user.Logins,
                ExternalProviders = externalProviders,
                DisplayName       = user.DisplayName(),
                IsHidden          = user.IsHidden(),
                HasPassword       = await userManager.HasPasswordAsync(user),
                HasPasswordAuth   = identityOptions.Value.AllowPasswordAuth,
                SuccessMessage    = successMessage
            };

            if (model != null)
            {
                SimpleMapper.Map(model, result);
            }

            return(result);
        }
        private async Task <ProfileVM> GetProfileVM(UserWithClaims user, ChangeProfileModel model = null, string errorMessage = null, string successMessage = null)
        {
            var taskForProviders = signInManager.GetExternalProvidersAsync();
            var taskForPassword  = userManager.HasPasswordAsync(user.Identity);
            var taskForLogins    = userManager.GetLoginsAsync(user.Identity);

            await Task.WhenAll(taskForProviders, taskForPassword, taskForLogins);

            var result = new ProfileVM
            {
                Id                = user.Id,
                Email             = user.Email,
                ErrorMessage      = errorMessage,
                ExternalLogins    = taskForLogins.Result,
                ExternalProviders = taskForProviders.Result,
                DisplayName       = user.DisplayName(),
                IsHidden          = user.IsHidden(),
                HasPassword       = taskForPassword.Result,
                HasPasswordAuth   = identityOptions.Value.AllowPasswordAuth,
                SuccessMessage    = successMessage
            };

            if (model != null)
            {
                SimpleMapper.Map(model, result);
            }

            return(result);
        }
示例#3
0
 public Task <IActionResult> UpdateProfile(ChangeProfileModel model)
 {
     return(MakeChangeAsync(user => userManager.UpdateAsync(user, model.Email, model.DisplayName, model.IsHidden),
                            "Account updated successfully."));
 }
示例#4
0
        private async Task <IActionResult> MakeChangeAsync(Func <IUser, Task <IdentityResult> > action, string successMessage, ChangeProfileModel model = null)
        {
            var user = await userManager.GetUserAsync(User);

            if (!ModelState.IsValid)
            {
                return(View(nameof(Profile), await GetProfileVM(user, model)));
            }

            string errorMessage;

            try
            {
                var result = await action(user);

                if (result.Succeeded)
                {
                    await signInManager.SignInAsync(user, true);

                    return(RedirectToAction(nameof(Profile), new { successMessage }));
                }

                errorMessage = string.Join(". ", result.Errors.Select(x => x.Description));
            }
            catch
            {
                errorMessage = "An unexpected exception occurred.";
            }

            return(View(nameof(Profile), await GetProfileVM(user, model, errorMessage)));
        }
示例#5
0
 public Task <IActionResult> UpdateProfile(ChangeProfileModel model)
 {
     return(MakeChangeAsync(id => userService.UpdateAsync(id, model.ToValues()),
                            T.Get("users.profile.updateProfileDone"), model));
 }
 public Task <IActionResult> UpdateProfile(ChangeProfileModel model)
 {
     return(MakeChangeAsync(user => userManager.UpdateSafeAsync(user.Identity, model.ToValues()),
                            "Account updated successfully."));
 }
 public Task <IActionResult> UpdateProfile(ChangeProfileModel model)
 {
     return(MakeChangeAsync(u => UpdateAsync(u, model.ToValues()),
                            "Account updated successfully.", model));
 }