public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await MessageServices.SendEmailAsync(model.Email, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); ViewBag.Link = callbackUrl; ViewBag.Code = code; ViewBag.UserId = user.Id; return(View("RegisterConfirmation")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new User { UserName = model.UserName, Email = model.Email, CreateOn = DateTime.Now, LastTime = DateTime.Now }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User {userName} was created.", model.Email); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await MessageServices.SendEmailAsync(model.Email, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); if (user.UserName.ToLower().Equals("admin")) { await UserManager.AddClaimAsync(user, new Claim("Admin", "Allowed")); } return(RedirectToAction("Login")); } AddErrors(result); } return(View(model)); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User {userName} was created.", model.Email); //Bug: Remember browser option missing? //Uncomment this and comment the later part if account verification is not needed. //await SignInManager.SignInAsync(user, isPersistent: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link string code = await UserManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); await MessageServices.SendEmailAsync(model.Email, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
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")); } var code = await UserManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code }, protocol: HttpContext.Request.Scheme); await MessageServices.SendEmailAsync(model.Email, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>"); ViewBag.Link = callbackUrl; return(View("ForgotPasswordConfirmation")); } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> 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=320771 // Send an email with this link string code = await UserManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPassword", "Account", new { code = code }, protocol: HttpContext.Request.Scheme); await MessageServices.SendEmailAsync(model.Email, "Reset Password", "Please reset your password by clicking here: <a href=\"" + callbackUrl + "\">link</a>"); #if !DEMO return(RedirectToAction("ForgotPasswordConfirmation")); #else //To display the email link in a friendly page instead of sending email ViewBag.Link = callbackUrl; return(View("DemoLinkDisplay")); #endif } ModelState.AddModelError("", string.Format("We could not locate an account with email : {0}", model.Email)); // 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(View("Error")); } // Generate the token and send it var code = await UserManager.GenerateTwoFactorTokenAsync(user, model.SelectedProvider); if (string.IsNullOrWhiteSpace(code)) { return(View("Error")); } var message = "Your security code is: " + code; if (model.SelectedProvider == "Email") { await MessageServices.SendEmailAsync(await UserManager.GetEmailAsync(user), "Security Code", message); } else if (model.SelectedProvider == "Phone") { await MessageServices.SendSmsAsync(await UserManager.GetPhoneNumberAsync(user), message); } return(RedirectToAction("VerifyCode", new { Provider = model.SelectedProvider, ReturnUrl = model.ReturnUrl, RememberMe = model.RememberMe })); }
public async System.Threading.Tasks.Task SendEmail(string fullName, string email, string template, string emailTitle) { var message = await EmailTemplate(template); message = message.Replace("UserFullName", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(fullName)); message = message.Replace("UserEmail", email); await MessageServices.SendEmailAsync(email, emailTitle, message); }
public async Task <ActionResult> SendEmail(SendEmailViewModel model) { var mesage = await EmailTemplate("WelcomeEmail"); mesage = mesage.Replace("ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.FirstName)); await MessageServices.SendEmailAsync(model.Email2, "Welcome!", mesage); return(View("EmailSent")); }
/// <summary> /// Send registration email. /// </summary> /// <param name="user">Information about newly registered used.</param> /// <param name="code">Token which could be used for the confirming email.</param> /// <returns>Asynchronous task which sends registration email.</returns> protected virtual async Task SendRegistrationEmail(TUser user, string code) { #if !NETCORE var callbackUrl = this.Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await this.UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); #else var callbackUrl = this.Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Scheme); await MessageServices.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); #endif }
/// <summary> /// Sends forgot password registration email. /// </summary> /// <param name="user">User which request forgot password email.</param> /// <param name="code">Code for forgot password registration.</param> /// <returns>Asynchronously send forgot password email.</returns> protected virtual async Task SendForgotPasswordEmail(TUser user, string code) { #if !NETCORE var callbackUrl = this.Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); await this.UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); #else var callbackUrl = this.Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Scheme); await MessageServices.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); #endif }
/// <summary> /// Sends forgot password registration email. /// </summary> /// <param name="user">User which request forgot password email.</param> /// <param name="code">Code for forgot password registration.</param> /// <returns>Asynchronously send forgot password email.</returns> protected virtual async Task SendResetPasswordEmail(TUser user, string code) { var callbackUrl = this.Url.Link("Default", new { @controller = "ResetPassword", @action = "Account", userId = user.Id, code = code }); #if !NETCORE await this.UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); #else await MessageServices.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>"); #endif }
public async Task <ActionResult> SendEmail(string fullName, string email) { var message = await EmailTemplate("RegisterEmailTemplate"); message = message.Replace("UserFullName", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(fullName)); message = message.Replace("UserEmail", email); await MessageServices.SendEmailAsync(email, "Registration request", message); return(RedirectToAction("Index", "Home")); }
/// <summary> /// envia emails /// </summary> /// <param name="model">define os dados a enviar no email</param> /// <returns></returns> public static async Task <int> SendEmail(SendEmailViewModel model) { int resultado = 0; //correu bem o envio do email // cria a mensagem do email com o template selecionado var message = await EmailTemplate(model.TemplateEmail); // envia o email await MessageServices.SendEmailAsync(model.Email, model.Assunto, message); return(resultado); }
/// <summary> /// Send password recovery email. /// </summary> /// <param name="provider">Sending provider.</param> /// <param name="user">User for which send notification.</param> /// <param name="code">Password recovery code.</param> /// <returns>Async task which send code.</returns> protected virtual async Task OnRecoveryCodeSent(string provider, TUser user, string code) { var message = "Your security code is: " + code; if (provider == "Email") { await MessageServices.SendEmailAsync(user.Email, "Security Code", message); } else if (provider == "Phone") { await MessageServices.SendSmsAsync(user.PhoneNumber, message); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var custEmail = FindEmail(model.RegisterEmail); var custUserName = FindUserName(model.RegisterUsername); var user = new ApplicationUser { UserName = model.RegisterUsername, Email = model.RegisterEmail, FirstName = model.FirstName, LastName = model.LastName, Country = model.Country, BirthDate = model.BirthDate, EmailLinkDate = DateTime.Now }; if (custEmail == null && custUserName == null) { var result = await UserManager.CreateAsync(user, model.RegisterPassword); if (result.Succeeded) { var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, date = DateTime.Now, code = code }, protocol: Request.Url.Scheme); var message = await EMailTemplate("WelcomeEmail"); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.FirstName)); message = message.Replace("@ViewBag.Link", callbackUrl); await MessageServices.SendEmailAsync(model.RegisterEmail, "Confirm your account", message); return(View("ConfirmationEmailSent")); } AddErrors(result); } else { if (custEmail != null) { ModelState.AddModelError("", "Email is already registered."); } if (custUserName != null) { ModelState.AddModelError("", "Username " + model.RegisterUsername.ToLower() + " is already taken."); } } } // If we got this far, something failed, redisplay form return(View(model)); }
public async Task <ActionResult> Troubleshooting(SendEMailViewModel model) { var message = await EMailTemplate("TroubleshootingEmail"); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Name)); message = message.Replace("@ViewBag.Email", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Email)); message = message.Replace("@ViewBag.ProblemArea", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.ProblemArea)); message = message.Replace("@ViewBag.Description", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Description)); string subj = model.SupportOption; await MessageServices.SendEmailAsync("*****@*****.**", subj, message); return(View("EmailSent")); }
public async Task <ActionResult> FeedBack(SendEMailViewModel model) { var message = await EMailTemplate("FeedBackEmail"); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Name)); message = message.Replace("@ViewBag.Email", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Email)); message = message.Replace("@ViewBag.Rating", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Rating)); message = message.Replace("@ViewBag.Comments", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(model.Comments)); string subj = model.SupportOption; await MessageServices.SendEmailAsync("*****@*****.**", subj, message); return(View("EmailSent")); }
public async Task SendEmail(string actionName, string controllerName, ApplicationUser user, string email, string emailTemplate, string emailSubject) { string code = null; if (codeType == "EmailConfirmation") { code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); } else if (codeType == "ResetPassword") { code = await UserManager.GeneratePasswordResetTokenAsync(user.Id); } var callbackUrl = Url.Action(actionName, controllerName, new { userId = user.Id, date = DateTime.Now, code = code }, protocol: Request.Url.Scheme); var message = await EMailTemplate(emailTemplate); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.FirstName)); message = message.Replace("@ViewBag.Link", callbackUrl); await MessageServices.SendEmailAsync(email, emailSubject, message); }
public async Task <IActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new User { UserName = model.UserName, Email = model.Email, CreateOn = DateTime.Now, LastTime = DateTime.Now }; //将用户名存储到identity的储存器中去 var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User {userName} was created.", model.Email); //生成用户的指定令牌 string code = await UserManager.GenerateEmailConfirmationTokenAsync(user); //通过使用指定的动作名称、控制器名称、路由值和使用的协议,为操作方法生成一个完全限定或绝对的URL。 将用户的userid和code传递到url上 var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme); // 提供邮件服务,注册成功后 向用户的邮箱里发送一封邮件 让他确认注册 await MessageServices.SendEmailAsync(model.Email, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>"); if (user.UserName.ToLower().Equals("wzl")) { //给指定用户添加权限 await UserManager.AddClaimAsync(user, new Claim("Admin", "Allowed")); } else if (user.UserName.ToLower().Equals("wss")) { //给指定用户添加权限 await UserManager.AddClaimAsync(user, new Claim("Wss", "Allowed")); } return(RedirectToAction("Login")); } AddErrors(result); } return(View(model)); }
public async Task <ActionResult> SendAskQuestionEmail(clsAskquestion model) { var message = await EmailTemplate("faqemail"); message = message.Replace("@ViewBag.Email", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.emailaddress)); message = message.Replace("@ViewBag.Ordernum", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.order)); message = message.Replace("@ViewBag.Reason", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.reason)); message = message.Replace("@ViewBag.Description", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.questionText)); await MessageServices.SendEmailAsync("*****@*****.**", "Welcome", message); return(View()); }
public async Task <ActionResult> Signup(User user) { if (ModelState.IsValid) { UserLayer userBusinessLayer = new UserLayer(); userBusinessLayer.AddUser(user); var message = await EmailTemplate("WelcomeEmail"); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (user.Fname)); await MessageServices.SendEmailAsync(user.Email, "Welcome", message); return(RedirectToAction("Index", "Home")); ModelState.Clear(); } return(View()); }
public async Task <ActionResult> SendConfirmationMail() { string res = null; string connection = GetConnectionString("DefaultConnection"); using (SqlConnection myConnection = new SqlConnection(connection)) using (SqlCommand cmd = new SqlCommand("SELECT Email AS Email FROM AspNetUsers WHERE UserName = @UserName", myConnection)) { cmd.Parameters.AddWithValue("@UserName", EConfUser); myConnection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { // Read advances to the next row. if (reader.Read()) { // To avoid unexpected bugs access columns by name. res = reader["Email"].ToString(); var user = await UserManager.FindByEmailAsync(res); UpdateEmailLinkDate(EConfUser); var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, date = DateTime.Now, code = code }, protocol: Request.Url.Scheme); var message = await EMailTemplate("WelcomeEmail"); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase(user.FirstName)); message = message.Replace("@ViewBag.Link", callbackUrl); await MessageServices.SendEmailAsync(res, "Confirm your account", message); } myConnection.Close(); } } } return(RedirectToAction("ConfirmationEmailSent", "Account")); }
public async Task <ActionResult> SendFeedbackEmail(clsSendFeedback model) { if (model.Rate != null && model.Feedbacktype != null && model.feedbacktext != null) { var message = await EmailTemplate("feedbackemail"); message = message.Replace("@ViewBag.Name", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.Feedbacktype)); message = message.Replace("@ViewBag.Description", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.feedbacktext)); message = message.Replace("@ViewBag.rate", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (model.Rate)); await MessageServices.SendEmailAsync("*****@*****.**", "Welcome", message); ViewData["Suceess"] = "Feedback sent"; return(View()); } ViewData["Exception"] = "All Fields Required"; return(View()); }
public async Task <ActionResult> PasswordRecovery(editUser user) { UserLayer ulayer = new UserLayer(); Random r = new Random(1001); int code = new Random().Next(1001, 9999); try { var result = ulayer.Users.Single(u => u.Email == user.Email); if (result != null) { ulayer.Updatecode(code, user.Email); var message = await EmailTemplate("RecoveryEmail"); message = message.Replace("@ViewBag.Code", CultureInfo.CurrentCulture.TextInfo.ToTitleCase (code.ToString())); await MessageServices.SendEmailAsync(user.Email, "Password Recovery", message); TempData["Email"] = "Email has been Sent successfully to " + user.Email + ". Please enter the recovery code. "; return(View("Recoverychange")); } } catch (Exception e) { ViewData["Exception"] = "This account does not exist. Please Sign Up"; } return(View()); }