public override int GetHashCode() { int hashcode = 157; unchecked { if (__isset.emailConfirmationType) { hashcode = (hashcode * 397) + EmailConfirmationType.GetHashCode(); } if (__isset.verifier) { hashcode = (hashcode * 397) + Verifier.GetHashCode(); } if (__isset.targetEmail) { hashcode = (hashcode * 397) + TargetEmail.GetHashCode(); } } return(hashcode); }
public async Task<string> GenerateEmailConfirmationTokenIfNotExistAsync(long userId, EmailConfirmationType type) { AssertUtil.AreBigger(userId, 0, "用户不存在"); EmailConfirmation ec = await Fetch(x => x.UserAccountID == userId && x.Type == type).FirstOrDefaultAsync(); if(ec != null) { return ec.Code; } else { EmailConfirmation emailConfirmation = new EmailConfirmation() { UserAccountID = userId, Code = Guid.NewGuid().ToString(), Type = type }; Add(emailConfirmation); return await SaveChangesAsync() > 0 ? emailConfirmation.Code : string.Empty; } }
public override string ToString() { var sb = new StringBuilder("EmailConfirmationSession("); bool __first = true; if (__isset.emailConfirmationType) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("EmailConfirmationType: "); EmailConfirmationType.ToString(sb); } if (Verifier != null && __isset.verifier) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("Verifier: "); Verifier.ToString(sb); } if (TargetEmail != null && __isset.targetEmail) { if (!__first) { sb.Append(", "); } __first = false; sb.Append("TargetEmail: "); TargetEmail.ToString(sb); } sb.Append(")"); return(sb.ToString()); }
private async Task<string> SendEmailConfirmationTokenAsync(long userId, string toEmailAddress, string subject, EmailConfirmationType type) { string code = await Services.SecurityClient.GenerateEmailConfirmationTokenIfNotExistAsync(userId, type); string callbackUrl = string.Empty; if(type == EmailConfirmationType.Register) { callbackUrl = Url.Action("ConfirmEmail", "Account", new { email = toEmailAddress, code = code }, protocol: Request.Url.Scheme); } else if(type == EmailConfirmationType.ResetPassword) { callbackUrl = Url.Action("ResetPassword", "Account", new { email = toEmailAddress, code = code }, protocol: Request.Url.Scheme); } try { await SMTPMailClient.SendAsync(subject, "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>", toEmailAddress, "", true); } catch (System.Net.Mail.SmtpFailedRecipientsException) { //AddErrors("验证邮件发送失败,请检查邮件是否正确"); } return callbackUrl; }
public async Task<string> GenerateEmailConfirmationTokenIfNotExistAsync(long userId, EmailConfirmationType type) { return await GetAsync<string>(RelativePaths.GenerateEmailConfirmationTokenIfNotExist.Link(userId, type)); }
public async Task<string> GenerateEmailConfirmationTokenIfNotExistAsync(long userId, EmailConfirmationType type) { return await new SecurityManager().GenerateEmailConfirmationTokenIfNotExistAsync(userId, type); }
/// <summary> /// 生成邮件验证码 /// </summary> /// <param name="userId">用户ID</param> /// <param name="type">验证码类型</param> /// <returns></returns> public async Task<string> GenerateEmailConfirmationTokenIfNotExistAsync(long userId, EmailConfirmationType type) { using(KoalaBlogDbContext dbContext = new KoalaBlogDbContext()) { EmailConfirmationHandler emailConfirmationHandler = new EmailConfirmationHandler(dbContext); return await emailConfirmationHandler.GenerateEmailConfirmationTokenIfNotExistAsync(userId, type); } }