public async Task <string> ForgotPassword(string email) { var user = await userManager.FindByEmailAsync(email); if (user == null) { return("user not found"); } var html = await File.ReadAllTextAsync("../Disco.BLL/EmailTemplates/ConfirmationEmail/index.html"); var passwordToken = await userManager.GeneratePasswordResetTokenAsync(user); string url = $"disco://disco.app/token/{passwordToken}"; EmailConfirmationModel model = new EmailConfirmationModel(); model.MessageHeader = "Email confirmation"; model.MessageBody = html.Replace("[token]", passwordToken).Replace("[email]", user.Email); model.ToEmail = email; model.IsHtmlTemplate = true; await emailService.EmailConfirmation(model); return(passwordToken); }
public async Task <IActionResult> ConfirmEmail([FromBody] EmailConfirmationModel emailConfirmationModel) { emailConfirmationModel.Token = emailConfirmationModel.Token.Replace(" ", "+"); var model = await _accountService.ConfirmEmailAsync(emailConfirmationModel); return(Ok(model)); }
public async Task <BaseModel> ConfirmEmailAsync(EmailConfirmationModel model) { var emailConfirmationModel = new EmailConfirmationModel(); var user = await _userRepository.FindByEmailAsync(model.Email); if (user == null) { emailConfirmationModel.Errors.Add(Constants.Errors.UsersNotExistError); return(emailConfirmationModel); } var result = await _userRepository.ConfirmEmailAsync(model.Email, model.Token); if (!result) { emailConfirmationModel.Errors.Add(Constants.Errors.EmailConfirmationError); } result = await _userRepository.UnlockAsync(user.Email); if (!result) { emailConfirmationModel.Errors.Add(Constants.Errors.UserLockError); return(emailConfirmationModel); } return(emailConfirmationModel); }
public MvcMailMessage ConfirmationTokenMessage(EmailConfirmationModel model) { ViewData.Model = model; return(Populate(x => { x.Subject = "Activate your account " + model.SiteName; x.ViewName = "ConfirmAccount"; x.To.Add(model.ToEmail); })); }
public async Task <bool> ConfirmEmail(EmailConfirmationModel model) { var user = await _userManager.FindByEmailAsync(model.Email); var decodedBytes = Convert.FromBase64String(model.Token); var token = Encoding.Unicode.GetString(decodedBytes); var result = await _userManager.ConfirmEmailAsync(user, token); return(result.Succeeded); }
public async Task <IActionResult> ConfirmEmail(EmailConfirmationModel model) { try { if (!ModelState.IsValid) { throw new InvalidOperationException("Input Parameters Not In Correct Format"); } var email = await EmailConfirmationService.ConfirmEmail(model.UserId, model.Token); string redirectUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.Value}/EmailConfirmationSuccessful"; EmailConfirmationResponse emailConfirmationResponse = new EmailConfirmationResponse { Email = email, ConfirmationStatus = EmailConfirmation.CONFIRMED }; return(Ok(emailConfirmationResponse, "Email Confirmed Successfully", ResponseStatus.OK)); } catch (InvalidOperationException ex) { EmailConfirmationResponse emailConfirmationResponse = new EmailConfirmationResponse { ConfirmationStatus = EmailConfirmation.UNCONFIRMED }; var user = await UserManager.FindByIdAsync(model.UserId); if (user != null) { emailConfirmationResponse.Email = user.Email; } return(BadRequest(emailConfirmationResponse, ex.Message, ResponseStatus.APP_ERROR)); } catch (Exception ex) { EmailConfirmationResponse emailConfirmationResponse = new EmailConfirmationResponse { ConfirmationStatus = EmailConfirmation.UNCONFIRMED }; var user = await UserManager.FindByIdAsync(model.UserId); if (user != null) { emailConfirmationResponse.Email = user.Email; } return(BadRequest(emailConfirmationResponse, "Oops Something Went Wrong", ResponseStatus.FATAL_ERROR)); } }
public Task SendEmailConfirmationAsync(EmailConfirmationModel emailConfirmationModel) { var sendEmailModel = new SendEmailModel { Email = emailConfirmationModel.Email, Subject = "Confirm your email", Message = $"Please confirm your account by clicking this link: <a href='{HtmlEncoder.Default.Encode(emailConfirmationModel.Link)}'>link</a>" }; return(SendEmailAsync(sendEmailModel)); }
public async Task <IActionResult> ForgotPassword([FromBody] EmailConfirmationModel user) { var resetPasswordModel = await _accountService.ResetPasswordAsync(user.Email); string subject = Constants.EmailHeaders.ResetingPasswordConfirmation; string body = $"New password: {resetPasswordModel.Password}. You can change it in account settings"; await _emailHelper.SendAsync(resetPasswordModel.Email, subject, body); return(Ok(resetPasswordModel)); }
public async Task <string> ConfirmEmailAsync(EmailConfirmationModel emailConfirmationModel) { var user = await _userManager.FindByEmailAsync(emailConfirmationModel.Email); if (user is null) { throw new Exception(Constants.Error.EMAILCONFIRMATION_USER_NOT_FOUND); } var result = await _userManager.ConfirmEmailAsync(user, emailConfirmationModel.Code); if (!result.Succeeded) { throw new Exception(Constants.Error.EMAILCONFIRMATION_EMAIL_DID_NOT_CONFIRMED); } return("email confirmed"); }
public ActionResult SendAccountConfirmationEmail(string username, string token) { Account account = AccountRepos.Get(username); EmailConfirmationModel model = new EmailConfirmationModel() { SiteName = siteName, SiteUrl = siteUrl, UserName = account.UserName, FirstName = account.FirstName, ToEmail = account.Email, ConfirmationToken = token, ConfirmationUrl = siteUrl + "/Account/ConfirmAccount?u=" + account.UserName + @"&t" + token }; UserMailer mailer = new UserMailer(); mailer.ConfirmationTokenMessage(model).Send(); return(RedirectToAction("RegistrationSuccess", "Account")); }
public async Task <EmailConfirmationModel> SignUpAsync(SignUpModel signUpModel) { var resultModel = new EmailConfirmationModel(); var user = await _userRepository.FindByEmailAsync(signUpModel.Email); if (user != null) { resultModel.Errors.Add(Constants.Errors.EmailExistsError); return(resultModel); } var result = await _userRepository.CreateAsync(signUpModel.MapToEntity(), signUpModel.Password); if (!result) { resultModel.Errors.Add(Constants.Errors.CreateUserError); return(resultModel); } user = await _userRepository.FindByEmailAsync(signUpModel.Email); if (user == null) { resultModel.Errors.Add(Constants.Errors.CreateUserError); return(resultModel); } result = await _userRepository.AddToRoleAsync(user.Id, Enums.Role.RoleName.Client.ToString()); if (!result) { resultModel.Errors.Add(Constants.Errors.CreateUserError); return(resultModel); } resultModel.Email = signUpModel.Email; resultModel.Token = await _userRepository.GenerateEmailConfirmationTokenAsync(user.Email); return(resultModel); }
public async Task <IActionResult> ConfirmEmail([FromBody] EmailConfirmationModel model) { if (model.UserId == null || model.Ctoken == null) { return(BadRequest()); } var user = await _userManager.FindByIdAsync(model.UserId); model.Ctoken = HttpUtility.UrlDecode(model.Ctoken); var res = await _userManager.ConfirmEmailAsync(user, model.Ctoken); if (res.Succeeded) { return(Ok()); } else { _logger.LogError("Invalid Email Content"); return(Content("Invalid Email Content")); } }
public async Task EmailConfirmation(EmailConfirmationModel model) { using (var client = new SmtpClient()) { MimeMessage message = new MimeMessage(); message.From.Add(new MailboxAddress("Disco", emailOptions.Value.Mail)); message.To.Add(new MailboxAddress(model.Name, model.ToEmail)); message.Subject = model.MessageHeader; message.Body = new TextPart(MimeKit.Text.TextFormat.Html) { Text = model.MessageBody }; client.Connect(emailOptions.Value.Host, emailOptions.Value.Port, true); client.AuthenticationMechanisms.Remove("XOAUTH2"); client.Authenticate(emailOptions.Value.Name, emailOptions.Value.Password); var result = await client.SendAsync(message); logger.LogInformation(result); client.Disconnect(true); } }
public async Task <IActionResult> ConfirmEmail([FromQuery] EmailConfirmationModel emailConfirmationModel) { var result = await _accountService.ConfirmEmailAsync(emailConfirmationModel); return(Ok(result)); }