private async Task <ItemResponse <Guid> > SendNewConfirmationEmail(string firstName, string lastName, string email, string id) { SecurityTokenAddRequest securityToken = new SecurityTokenAddRequest(); securityToken.FirstName = firstName; securityToken.LastName = lastName; securityToken.Email = email; securityToken.TokenTypeId = 1; securityToken.AspNetUserId = id; Guid emailSecurityToken = SecurityTokenService.Insert(securityToken); ConfirmationEmailRequest emailRequest = new ConfirmationEmailRequest(); emailRequest.FirstName = firstName; emailRequest.LastName = lastName; emailRequest.Email = email; emailRequest.SecurityToken = emailSecurityToken; //Removed static to enable DI await _emailService.ConfirmRegistration(emailRequest); ItemResponse <Guid> response = new ItemResponse <Guid>(); response.Item = emailSecurityToken; return(response); }
private async Task <ItemResponse <Guid> > SendResetPasswordEmail(PersonBase pb, ConfirmationEmailRequest model) { SecurityTokenAddRequest securityToken = new SecurityTokenAddRequest(); securityToken.FirstName = pb.FirstName; securityToken.LastName = pb.LastName; securityToken.Email = model.Email; securityToken.TokenTypeId = 2; securityToken.AspNetUserId = ""; Guid emailSecurityToken = SecurityTokenService.Insert(securityToken); ConfirmationEmailRequest emailRequest = new ConfirmationEmailRequest(); emailRequest.FirstName = pb.FirstName; emailRequest.LastName = pb.LastName; emailRequest.Email = model.Email; emailRequest.SecurityToken = emailSecurityToken; await _emailService.ForgotPassword(emailRequest); ItemResponse <Guid> response = new ItemResponse <Guid>(); response.Item = emailSecurityToken; return(response); }
public string ForgotPasswordSendEmail(ForgottenPasswordEmailTokenAddRequest model) { SecurityTokenService sts = new SecurityTokenService(_dataProvider); SecurityTokenAddRequest star = new SecurityTokenAddRequest() { TokenTypeId = 2, UserEmail = model.Email }; System.Guid tokenGuid = sts.Insert(star); var source = "http://sawubona.dev/"; var message = "<body style='margin: 0; padding: 0; background:#ccc;'><table cellpadding=0 cellspacing=0 style='width: 100%;'><tr><td style='padding: 12px 2%;'><table cellpadding=0 cellspacing=0 style='margin:auto; background: #fff; width: 96%;'><tr><td style='padding: 12px 2%;'><div><h1 style='color:white;background-color:#1E90FF;'>Youth Mentoring Connection</h1></div > <div><h2 style='margin-top: 0;'>Password Reset</h2><p>To reset your password please click the link below:<br/></br> <span style='text-align:center; margin:0;'><a href=" + source + "forgottenPasswords?guid=" + tokenGuid + "/" + model.Email + ">Click Here To Reset Password</a></p><p>...</p></div><div><h4 style='margin-top: 0;'>Sawubona!</h4><p></p></div><div style='border-top: solid 1px #ccc;'><p></p></div></td ></tr ></table ></td ></tr ></table ></body >"; ConfirmationEmailService ces = new ConfirmationEmailService(); ConfirmationEmailRequest cer = new ConfirmationEmailRequest() { From = "*****@*****.**", To = model.Email, Subject = "YMC Confirmation", Body = message }; Task<bool> email = ces.Execute(cer); return model.Email; }
private bool SendEmailConfirmationEmail(string email) { //1) creating token SecurityTokenService sts = new SecurityTokenService(_dataProvider); SecurityTokenAddRequest star = new SecurityTokenAddRequest() { TokenTypeId = 1, UserEmail = email }; System.Guid tokenGuid = sts.Insert(star); //2) emailing confirmation var source = SiteConfig.BaseUrl; var message = "<body style='margin: 0; padding: 0; background:#ccc;'><table cellpadding=0 cellspacing=0 style='width: 100%;'><tr><td style='padding: 12px 2%;'><table cellpadding=0 cellspacing=0 style='margin:auto; background: #fff; width: 96%;'><tr><td style='padding: 12px 2%;'><div><h1 style='color:white;background-color:#1E90FF;'>Personality App</h1></div > <div><h2 style='margin-top: 0;'>Congratulations</h2><p>You've successfully registered. Please confirm your email with the Personality App.To confirm your email click the link below:<br/></br> <span style='text-align:center; margin:0;'><a href=" + source + "/confirmationPages?guid=" + tokenGuid + ">Click Here To Confirm Email</a></p><p>...</p></div><div><h4 style='margin-top: 0;'>Sawubona!</h4><p></p></div><div style='border-top: solid 1px #ccc;'><p></p></div></td ></tr ></table ></td ></tr ></table ></body >"; ConfirmationEmailService ces = new ConfirmationEmailService(); ConfirmationEmailRequest cer = new ConfirmationEmailRequest() { From = SiteConfig.SiteAdminEmailAddress, To = email, Subject = "DJ MESSAGE", Body = message }; Task<bool> success = ces.Execute(cer); while (success == null) { return false; } return true; }
public async Task <HttpResponseMessage> VerifyUser(ConfirmationEmailRequest model) { if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)); } PersonBase pb = UserService.SelectByEmail(model.Email); if (pb == null) { ErrorResponse er = new ErrorResponse("This email is not associated with an account."); return(Request.CreateResponse(HttpStatusCode.BadRequest, er)); } ItemResponse <Guid> response = await SendResetPasswordEmail(pb, model); return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public async Task <HttpResponseMessage> ResendResetPasswordEmail(Guid guid) { SecurityToken securityToken = SecurityTokenService.SelectByGuid(guid); PersonBase pb = new PersonBase(); pb.FirstName = securityToken.FirstName; pb.LastName = securityToken.LastName; pb.Email = securityToken.Email; ConfirmationEmailRequest r = new ConfirmationEmailRequest(); r.Email = securityToken.Email; ItemResponse <Guid> response = await SendResetPasswordEmail(pb, r); return(Request.CreateResponse(HttpStatusCode.OK, response)); }
public async Task <bool> Execute(ConfirmationEmailRequest model) { var apiKey = ConfigurationManager.AppSettings["djKey"].ToString(); //Grab Key From Web.Config var client = new SendGridClient(apiKey); var from = new EmailAddress("*****@*****.**"); var subject = model.Subject; var to = new EmailAddress(model.To); var plainTextContent = model.Body; var htmlContent = model.Body; var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); SendGrid.Response response = await client.SendEmailAsync(msg); if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.OK) { return(true); } return(false); }
public async Task <bool> ForgotPassword(ConfirmationEmailRequest model) { // Setup HTML message string url = System.Web.Configuration.WebConfigurationManager.AppSettings["BaseUrl"] + "/users/resetpassword/" + model.SecurityToken; string path = HttpContext.Current.Server.MapPath("~/HTML_Templates/ResetPasswordEmail.html"); string emailBody = System.IO.File.ReadAllText(path); string finalEmail = emailBody.Replace("{{firstName}}", model.FirstName) .Replace("{{confirmUrl}}", url); // Send to Email Sender string name = "Operation Code"; string toName = model.FirstName + " " + model.LastName; string toAddress = model.Email; string fromAddress = System.Web.Configuration.WebConfigurationManager.AppSettings["SiteAdminEmailAddress"]; string subject = "Reset Your Deploy Password"; string messageText = "Please click the following link to reset your password: "******"BaseUrl"] + "/users/resetpassword/" + model.SecurityToken; string messageHtml = finalEmail; return(await Send(fromAddress, name, toName, toAddress, subject, messageText, messageHtml)); }
public int Create(AccountUpsertRequest userModel) { int userId = 0; string salt; string passwordHash; string password = userModel.Password; salt = _cryptographyService.GenerateRandomString(RAND_LENGTH); passwordHash = _cryptographyService.Hash(password, salt, HASH_ITERATION_COUNT); _dataProvider.ExecuteNonQuery("dbo.Person_UpsertAccount", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Id", userModel.Id); paramCollection.AddWithValue("@FirstName", userModel.FirstName); paramCollection.AddWithValue("@LastName", userModel.LastName); paramCollection.AddWithValue("@Email", userModel.Email); paramCollection.AddWithValue("@Salt", salt); paramCollection.AddWithValue("@PasswordHash", passwordHash); paramCollection.AddWithValue("@RoleId", userModel.RoleId); //SqlParameter idParameter = new SqlParameter("@Id", SqlDbType.Int); //idParameter.Direction = ParameterDirection.Output; //paramCollection.Add(idParameter); } //, //returnParameters: delegate (SqlParameterCollection param) //{ // Int32.TryParse(param["@Id"].Value.ToString(), out userId); //} ); //1)creating token SecurityTokenService sts = new SecurityTokenService(_dataProvider); SecurityTokenAddRequest star = new SecurityTokenAddRequest() { TokenTypeId = 1, UserEmail = userModel.Email }; System.Guid tokenGuid = sts.Insert(star); //2)emailing confirmation var source = SiteConfig.BaseUrl; var message = "<body style='margin: 0; padding: 0; background:#ccc;'><table cellpadding=0 cellspacing=0 style='width: 100%;'><tr><td style='padding: 12px 2%;'><table cellpadding=0 cellspacing=0 style='margin:auto; background: #fff; width: 96%;'><tr><td style='padding: 12px 2%;'><div><h1 style='color:white;background-color:#1E90FF;'>Youth Mentoring Connection</h1></div > <div><h2 style='margin-top: 0;'>Congratulations</h2><p>You've successfully registered. Please confirm your email with Youth Mentoring Connection.To confirm your email click the link below:<br/></br> <span style='text-align:center; margin:0;'><a href=" + source + "/confirmationPages?guid=" + tokenGuid + ">Click Here To Confirm Email</a></p><p>...</p></div><div><h4 style='margin-top: 0;'>Sawubona!</h4><p></p></div><div style='border-top: solid 1px #ccc;'><p></p></div></td ></tr ></table ></td ></tr ></table ></body >"; ConfirmationEmailService ces = new ConfirmationEmailService(); ConfirmationEmailRequest cer = new ConfirmationEmailRequest() { From = "*****@*****.**", To = userModel.Email, Subject = "YMC Confirmation", Body = message }; Task <bool> email = ces.Execute(cer); return(userId); //DB provider call to create user and get us a user id //be sure to store both salt and passwordHash //DO NOT STORE the original password value that the user passed us }