public async Task UpdateUserProfile(UpdateUserProfileInput input) { var user = await UserManager.GetUserByIdAsync(StudioXSession.GetUserId()); var mapped = input.MapTo(user); await UserManager.UpdateAsync(mapped); }
protected virtual Task <User> GetCurrentUserAsync() { var user = UserManager.FindByIdAsync(StudioXSession.GetUserId().ToString()); if (user == null) { throw new Exception("There is no current user!"); } return(user); }
public async Task ChangePassword(ChangePasswordInput input) { var user = await UserManager.GetUserByIdAsync(StudioXSession.GetUserId()); var hashedPassword = passwordHasher.HashPassword(user, input.Password); var verificationResult = passwordHasher.VerifyHashedPassword(user, hashedPassword, input.Password); if (verificationResult != PasswordVerificationResult.Success) { throw new UserFriendlyException("Current password must match old password!"); } var identityResult = await UserManager.ChangePasswordAsync(user, input.NewPassword); if (!identityResult.Succeeded) { throw new UserFriendlyException(identityResult.Errors.JoinAsString(", ")); } }
/// <summary> /// Gets current user if <see cref="IStudioXSession.UserId"/> is not null. /// Throws exception if it's null. /// </summary> protected async Task <User> GetCurrentUserAsync() { var userId = StudioXSession.GetUserId(); return(await UsingDbContext(context => context.Users.SingleAsync(u => u.Id == userId))); }
/// <summary> /// Gets current user if <see cref="IStudioXSession.UserId"/> is not null. /// Throws exception if it's null. /// </summary> protected User GetCurrentUser() { var userId = StudioXSession.GetUserId(); return(UsingDbContext(context => context.Users.Single(u => u.Id == userId))); }