public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); if (user == null)// || !(await UserManager.IsEmailConfirmedAsync(user))) { // Don't reveal that the user does not exist or is not confirmed return(View("ForgotPasswordConfirmation")); } // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link var code = await UserManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action(nameof(ResetPassword), Name, new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await EmailSender.SendEmailCommunicationAsync( SystemCommunicationPurposes.UserPasswordReset, CommunicationModelFactory.CreateCallbackUrlModel(callbackUrl), model.Email, null, user.ContactId); return(View(nameof(ForgotPasswordConfirmation))); } // If we got this far, something failed, redisplay form return(View(model)); }
private async Task SendInvitation(ApplicationUser user, string invitationText, string email) { var code = await UserManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action(nameof(AccountController.AcceptInvitation), AccountController.Name, new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await EmailSender.SendEmailCommunicationAsync( SystemCommunicationPurposes.UserAcceptInvitation, CommunicationModelFactory.CreateCallbackUrlModel(callbackUrl, invitationText), email, null, user.ContactId); }
public async Task <IActionResult> SendDirectMessage( int id, int templateId, string subject, string body) { var contact = await FindContactByIdAsync(id); if (contact == null) { return(NotFound()); } var model = CommunicationModelFactory.CreateSimpleContentModel(subject, body); await EmailSender.SendEmailCommunicationAsync(SystemCommunicationPurposes.DirectMessage, model, contact.PrimaryEmail, contact.FullName, contact.ContactId); return(Ok()); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { if (!Current.Application.AppSettings.Registration.UsersCanSelfRegister) { throw new NotNowException(MessageStrings.UserSelfRegistrationDisabled); } ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link if (Current.Tenant.TenantSettings.RequiresEmailAccountValidation) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action(nameof(ConfirmEmail), Name, new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await EmailSender.SendEmailCommunicationAsync( SystemCommunicationPurposes.UserAccountVerification, CommunicationModelFactory.CreateCallbackUrlModel(callbackUrl), model.Email); SetToast(MessageStrings.CheckEmailForVerification); } else { await SignInManager.SignInAsync(user, isPersistent : IsSigninPersistent); SetToast(MessageStrings.AccountCreated); } Logger.Information("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> SendCode(SendCodeViewModel model) { if (!ModelState.IsValid) { return(View()); } var user = await SignInManager.GetTwoFactorAuthenticationUserAsync(); if (user == null) { return(ErrorResult()); } // Generate the token and send it var code = await UserManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider); if (string.IsNullOrWhiteSpace(code)) { return(ErrorResult()); } if (model.SelectedProvider == "Email") { await EmailSender.SendEmailCommunicationAsync( SystemCommunicationPurposes.UserTwoFactorLoginCode, CommunicationModelFactory.CreateSimpleCodeModel(code), await UserManager.GetEmailAsync(user)); } else if (model.SelectedProvider == "Phone") { await SmsSender.SendSmsCommunicationAsync( SystemCommunicationPurposes.UserTwoFactorLoginCode, CommunicationModelFactory.CreateSimpleCodeModel(code), await UserManager.GetPhoneNumberAsync(user)); } return(RedirectToAction(nameof(VerifyCode), new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe })); }