public void Activate(string token) { if (!ActivationToken.Equals(token)) { throw new ArgumentException(string.Format("Tokens do not match. Activation Token={0}, token={1}", ActivationToken, token), "token"); } AccountStatus = AccountStatus.Activated; Activated = DateTime.UtcNow; ActivationToken = string.Empty; UpdateVersion(); }
public async Task <ActivationToken> GenerateActivationToken(string UserId) { var token = new ActivationToken() { Id = Guid.NewGuid().ToString(), UserId = UserId, CreatedAt = DateTime.Now, }; await _context.ActivationTokens.AddAsync(token); await _context.SaveChangesAsync(); return(token); }
/// <summary> /// Constructor. /// </summary> public UserService( DatabaseContext dbContext, IIdentityProvider identityProvider, IGitHubUserClient gitHubUserClient, IGitHubOrganizationClient gitHubOrgClient, IGitHubTeamClient gitHubTeamClient, IEmailProvider emailProvider, ActivationToken activationToken) { _dbContext = dbContext; _identityProvider = identityProvider; _gitHubUserClient = gitHubUserClient; _gitHubOrgClient = gitHubOrgClient; _gitHubTeamClient = gitHubTeamClient; _emailProvider = emailProvider; _activationToken = activationToken; }
public async Task <Response> SendActivationEmail(User recipient, ActivationToken token) { var apiKey = Configuration["SendGridApiKey"]; var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**", "Mxstrong"); var subject = "Activate your Mxstrong account"; var to = new EmailAddress(recipient.Email); var plainTextContent = $"Hello, {recipient.FullName}," + " To complete your registration click on a link below." + " If you did not intend to create Mxstrong account, ignore this letter"; var htmlContent = $"<html><body><h2 style=\"font-size: 36\">Hello, {recipient.FullName},</h2><br>" + "<div style=\"font-size: 20;\">To complete your registration " + $"<a style=\"color: blue\" href=\"https://mxstrong.azurewebsites.net/api/auth/activate/{token.Id}\">click here</a><br><br>" + "If you did not intend to create Mxstrong account, ignore this letter.</div></body></html>"; var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); var response = await client.SendEmailAsync(msg); return(response); }