private void EmailSetupForRegisterdUser(PgrmIdentityMessage message, string code, string action) { var callbackUrl = Url.Action(action, "Account", new { userId = message.Destination, code }, protocol: Request.Url.Scheme); message.Subject = EmailRes.ResetPWD_RegisterdUserSubjectFormat; message.Body = String.Format(EmailRes.ResetPWD_RegisterdUserBodyFormat, callbackUrl); }
private void EmailSetupForNotVerifiedUser(PgrmIdentityMessage message, string userID, string code) { var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = userID, code }, protocol: Request.Url.Scheme); message.Subject = EmailRes.ResetPWD_NotVerifiedUserSubjectFormat; message.Body = String.Format(EmailRes.ResetPWD_NotVerifiedUserBodyFormat, callbackUrl, Url.Action("Index", "Home", null, protocol: Request.Url.Scheme), Url.Action("ForgotPassword", "Account", null, protocol: Request.Url.Scheme)); }
private void EmailSetupForNotRegisterdUser(PgrmIdentityMessage message) { var callbackUrl = Url.Action("Register", "Account", null, protocol: Request.Url.Scheme); message.Subject = EmailRes.ResetPWD_NotRegisterdUserSubjectFormat; message.Body = String.Format(EmailRes.ResetPWD_NotRegisterdUserBodyFormat, callbackUrl); }
/// <summary> /// Email sent to oganization users (or site admins) for access (HPCDS-22) /// </summary> /// <param name="user"></param> /// <returns></returns> private async Task <bool> SendApprovedEmail(ApplicationUser user) { bool isSentToAdmins = false; var roleIds = DataProviderAuth.GetAppRolesFor(new List <string>(new string[] { UserRoles.PendingAccess }), false).Select(s => s.Id); string DestinationEmails = string.Join("; ", user.Organization .Users .Where(w => w.LockoutEndDateUtc == null && w.EmailConfirmed && w.Roles.Any(a => roleIds.Contains(a.RoleId))) // HPCDS-22 TODO: specify a better way of IDentify'n active users .Select(s => s.Email).ToList()); if (String.IsNullOrWhiteSpace(DestinationEmails)) { var adminUsers = DataProviderAuth.GetAdminUsers(); DestinationEmails = string.Join("; ", adminUsers.Select(s => s.Email).ToList()); isSentToAdmins = true; } var emailMsg = new PgrmIdentityMessage() { Destination = DestinationEmails, Subject = isSentToAdmins ? EmailRes.RegistrationApprovalReqForAdminSubjectFormat : EmailRes.RegistrationApprovalReqForOrgUsersSubjectFormat, Body = String.Format(isSentToAdmins ? EmailRes.RegistrationApprovalReqForAdminBodyFormat : EmailRes.RegistrationApprovalReqForOrgUsersBodyFormat //"email: {0} organization name: {1} urlControllerAction: {2} token: {3}" , user.Email, user?.Organization.OrganizationName ?? "ERROR-NO Organization Name", "URL-TODO: (HPCDS-25)", "TOKEN-APPROVE-USER"), }; await EService.SendAsync(emailMsg); #if DEBUG TempData["DebugMessage"] = emailMsg.ToStringEmail(); #endif return(true); }
public async Task <ActionResult> SendResetLink(SendResetLinkViewModel model) { var user = UserManager.FindById(model.SelectedUserId); string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); var emailObj = new PgrmIdentityMessage { Destination = user.Email }; EmailSetupForRegisterdUser(emailObj, code, "ResetPasswordByAdmin"); #if DEBUG ViewBag.DebugMessage = emailObj.ToStringEmail(); #endif await UserManager.SendEmailAsync(user.Id, emailObj.Subject, emailObj.Body); model.Users = AllUsersList(); model.IsSend = true; return(View(model)); }
public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await UserManager.FindByNameAsync(model.Email); var emailMsg = new PgrmIdentityMessage { Destination = user?.Email ?? model.Email }; if (user == null) { // Don't reveal that the user does not exist or is not confirmed EmailSetupForNotRegisterdUser(emailMsg); await EService.SendAsync(emailMsg); } else if (!(await UserManager.IsEmailConfirmedAsync(user.Id))) { string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); EmailSetupForNotVerifiedUser(emailMsg, user.Id, code); await UserManager.SendEmailAsync(user.Id, emailMsg.Subject, emailMsg.Body); } else { //For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateUserTokenAsync("CanAnswerSecQuestions", user.Id); EmailSetupForRegisterdUser(emailMsg, code, "VerifyUser"); await UserManager.SendEmailAsync(user.Id, emailMsg.Subject, emailMsg.Body); } #if DEBUG TempData["DebugMessage"] = emailMsg.ToStringEmail(); #endif return(RedirectToAction("ForgotPasswordConfirmation", "Account")); } // If we got this far, something failed, redisplay form return(View(model)); }
private async Task <bool> SendConfrimEmail(ApplicationUser user) { // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); var emailMsg = new PgrmIdentityMessage() { Destination = user.Email, Subject = EmailRes.EmailValidationSubjectFormat, Body = String.Format(EmailRes.EmailValidationBodyFormat, callbackUrl) }; await UserManager.SendEmailAsync(user.Id, emailMsg.Subject, emailMsg.Body); #if DEBUG TempData["DebugMessage"] = emailMsg.ToStringEmail(); #endif return(true); }