protected virtual Task AddCustomClaimsAsync(List <Claim> customClaims, IdentityUser user, ResourceOwnerPasswordValidationContext context) { if (user.TenantId.HasValue) { customClaims.Add(new Claim(AbpClaimTypes.TenantId, user.TenantId?.ToString())); } return(Task.CompletedTask); }
protected override async Task <string> GetCacheKeyAsync(string purpose, UserManager <IdentityUser> manager, IdentityUser user) { if (manager == null) { throw new ArgumentNullException(nameof(manager)); } var email = await manager.GetEmailAsync(user); return("Email:" + purpose + ":" + email); }
[UnitOfWork] //TODO: Will be removed when we implement action filter public virtual async Task <IActionResult> OnPostAsync() { ValidateModel(); await CheckSelfRegistrationAsync(); var user = new IdentityUser(GuidGenerator.Create(), Input.UserName, Input.EmailAddress, CurrentTenant.Id); (await UserManager.CreateAsync(user, Input.Password)).CheckErrors(); await UserManager.SetEmailAsync(user, Input.EmailAddress); await SignInManager.SignInAsync(user, isPersistent : false); return(Redirect(ReturnUrl ?? "/")); //TODO: How to ensure safety? IdentityServer requires it however it should be checked somehow! }
private async Task SendEmailToAskForEmailConfirmationAsync(Volo.Abp.Identity.IdentityUser user) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page("/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); AnotherEmailService anotherEmailService = new AnotherEmailService(); anotherEmailService.Send("*****@*****.**", Input.EmailAddress, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); /* // TODO use EmailService instead of using IEmailSender directly * await _emailSender.SendAsync(Input.EmailAddress, "Confirm your email", * $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");*/ }
protected override async Task RegisterLocalUserAsync() { ValidateModel(); var userDto = await AccountAppService.RegisterAsync( new RegisterDto { AppName = "Abp.EmailMarketing", EmailAddress = Input.EmailAddress, Password = Input.Password, UserName = Input.UserName } ); _abpIdentityUser = await UserManager.GetByIdAsync(userDto.Id); // Send user an email to confirm email address await SendEmailToAskForEmailConfirmationAsync(_abpIdentityUser); }
/// <summary> /// 修改用户密码,无需提供用户当前密码 /// </summary> /// <param name="userManager"></param> /// <param name="user">要修改密码的用户对象</param> /// <param name="password">修改后的密码</param> /// <returns></returns> public static async Task <IdentityResult> ChangePasswordAsync1(this UserManager <Volo.Abp.Identity.IdentityUser> userManager, Volo.Abp.Identity.IdentityUser user, string password) { var type = userManager.GetType(); var storeProperty = type.GetProperty("Store", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); var store = storeProperty.GetValue(userManager) as IUserPasswordStore <Volo.Abp.Identity.IdentityUser>; if (store == null) { return(IdentityResult.Failed(new IdentityError { Code = "NotImplements", Description = "持久化存储器没有实现IUserPasswordStore接口" })); } var passwordHash = userManager.PasswordHasher.HashPassword(user, password); await store.SetPasswordHashAsync(user, passwordHash, System.Threading.CancellationToken.None); await store.UpdateAsync(user, System.Threading.CancellationToken.None); return(IdentityResult.Success); }
public override async Task <bool> CanGenerateTwoFactorTokenAsync(UserManager <IdentityUser> manager, IdentityUser user) { if (manager == null) { throw new ArgumentNullException(nameof(manager)); } var email = await manager.GetEmailAsync(user); return(!string.IsNullOrWhiteSpace(email) && await manager.IsEmailConfirmedAsync(user)); }