public async Task <AccountResponse> ForgotPassword(string userName, string url) { var userToReset = await _accountProvider.Find(userName); string code = await _accountProvider.GeneratePasswordResetToken(userToReset.Id); var callbackUrl = string.Format("{0}{1}/{2}?userId={3}&code={4}", url, "Account", "ResetPassword", userToReset.Id, UtilityHelper.EncodeUrlCode(code)); IProcessEmail processEmail = new ProcessEmail(userName); processEmail.SendPasswordResetEmail(userToReset, callbackUrl); return(new AccountResponse { Success = true, }); }
public async Task <AccountResponse> RequestEmailConfirmation(string userName, string url) { var recipientUser = await _accountProvider.Find(userName); string emailConfirmationToken = await _accountProvider.GenerateEmailConfirmationToken(recipientUser.Id); var callback = string.Format("{0}{1}/{2}?userId={3}&code={4}", url, "Account", "ConfirmEmail", recipientUser.Id, UtilityHelper.EncodeUrlCode(emailConfirmationToken)); IProcessEmail processEmail = new ProcessEmail(userName); processEmail.SendEmailConfirmationEmail(recipientUser, callback); return(new AccountResponse { Success = true, }); }
public ApplicationUser CreateUser(ApplicationUser user) { UtilityHelper utilityHelper = new UtilityHelper(); string temporaryCode = utilityHelper.GeneratePassword(); user.TemporaryCode = temporaryCode; user = _userRepository.Create(user); Errors = ((IUserErrors)_userRepository).Errors; if (!string.IsNullOrWhiteSpace(user.Id)) { IProcessEmail processEmail = new ProcessEmail(user.UserName); processEmail.SendNewAccountSetupEmail(user); } SeedUserSettings seedUserSettings = new SeedUserSettings(user.Id); return(user); }
public async Task <string> FunctionHandler(S3Event evnt, ILambdaContext context) { var s3Event = evnt.Records?[0].S3; if (s3Event == null) { return(null); } if (await GetSecrets()) { if (s3Event.Bucket.Name.Contains("nnc")) { sqsRegion = RegionEndpoint.EUWest2; s3EmailsRegion = RegionEndpoint.EUWest2; s3TemplatesRegion = RegionEndpoint.EUWest2; pendingimagesbucket = secrets.nncpendingimagesbucket; quarantinedimagesbucket = secrets.nncquarantinedimagesbucket; templatesbucket = secrets.nncTemplateBucketTest; } else { sqsRegion = RegionEndpoint.EUWest1; s3EmailsRegion = RegionEndpoint.EUWest1; s3TemplatesRegion = RegionEndpoint.EUWest2; pendingimagesbucket = secrets.wncpendingimagesbucket; quarantinedimagesbucket = secrets.wncquarantinedimagesbucket; templatesbucket = secrets.templateBucketTest; } try { GetObjectMetadataResponse response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key); AmazonSQSClient amazonSQSClient = new AmazonSQSClient(sqsRegion); ProcessEmail emailProcessor = new ProcessEmail(); Console.WriteLine("Image Moderation Confidence Parameter = " + secrets.imageModerationConfidence); long imageModerationLevel = long.Parse(secrets.imageModerationConfidence); String sqsFAQURL = secrets.sqsFAQURLbeta; sqsEmailURL = secrets.sqsEmailURLTest; try { if (context.InvokedFunctionArn.ToLower().Contains("prod")) { Console.WriteLine("Prod version"); sqsFAQURL = secrets.sqsFAQURLprod; sqsEmailURL = secrets.sqsEmailURLLive; if (s3Event.Bucket.Name.Contains("nnc")) { templatesbucket = secrets.nncTemplateBucketLive; } else { templatesbucket = secrets.templateBucketLive; } } } catch (Exception) { Console.WriteLine("Beta version"); } if (emailProcessor.Process(s3Event.Bucket.Name, s3Event.Object.Key, imageModerationLevel, pendingimagesbucket, quarantinedimagesbucket, templatesbucket, s3EmailsRegion, s3TemplatesRegion)) { SendMessageRequest sendMessageRequest = new SendMessageRequest { QueueUrl = sqsFAQURL }; sendMessageRequest.MessageBody = "Email has passed validation. Waiting to be checked against FAQ database"; Dictionary <string, MessageAttributeValue> MessageAttributes = new Dictionary <string, MessageAttributeValue>(); MessageAttributeValue messageTypeAttribute1 = new MessageAttributeValue { DataType = "String", StringValue = "email" }; MessageAttributes.Add("Type", messageTypeAttribute1); MessageAttributeValue messageTypeAttribute2 = new MessageAttributeValue { DataType = "String", StringValue = s3Event.Bucket.Name }; MessageAttributes.Add("Bucket", messageTypeAttribute2); MessageAttributeValue messageTypeAttribute3 = new MessageAttributeValue { DataType = "String", StringValue = s3Event.Object.Key }; MessageAttributes.Add("Object", messageTypeAttribute3); String unitaryCouncil = ""; if (emailProcessor.west) { unitaryCouncil = "west"; } else { unitaryCouncil = "north"; } MessageAttributeValue messageTypeAttribute4 = new MessageAttributeValue { DataType = "String", StringValue = unitaryCouncil }; MessageAttributes.Add("UnitaryCouncil", messageTypeAttribute4); sendMessageRequest.MessageAttributes = MessageAttributes; SendMessageResponse sendMessageResponse = await amazonSQSClient.SendMessageAsync(sendMessageRequest); return("{\"Message\":\"Email passed checks\",\"lambdaResult\":\"Success\"}"); } else { try { SendMessageRequest sendMessageRequest = new SendMessageRequest { QueueUrl = sqsEmailURL }; sendMessageRequest.MessageBody = emailProcessor.emailBody; Dictionary <string, MessageAttributeValue> MessageAttributes = new Dictionary <string, MessageAttributeValue>(); MessageAttributeValue messageTypeAttribute1 = new MessageAttributeValue { DataType = "String", StringValue = emailProcessor.name }; MessageAttributes.Add("Name", messageTypeAttribute1); MessageAttributeValue messageTypeAttribute2 = new MessageAttributeValue { DataType = "String", StringValue = emailProcessor.emailTo }; MessageAttributes.Add("To", messageTypeAttribute2); MessageAttributeValue messageTypeAttribute3 = new MessageAttributeValue { DataType = "String", StringValue = "Re - " + emailProcessor.subject }; MessageAttributes.Add("Subject", messageTypeAttribute3); sendMessageRequest.MessageAttributes = MessageAttributes; SendMessageResponse sendMessageResponse = await amazonSQSClient.SendMessageAsync(sendMessageRequest); return("{\"Message\":\"Email did not pass checks\",\"lambdaResult\":\"Success\"}"); } catch (Exception error) { context.Logger.LogLine($"Error writing to queue {sqsEmailURL}."); context.Logger.LogLine(error.Message); context.Logger.LogLine(error.StackTrace); return("{\"Message\":\"Error writing to queue\",\"lambdaResult\":\"Success\"}"); } } } catch (Exception e) { context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}."); context.Logger.LogLine(e.Message); context.Logger.LogLine(e.StackTrace); return("{\"Message\":\"Error getting object\",\"lambdaResult\":\"Success\"}"); } } else { return("{\"Message\":\"Error getting secrets\",\"lambdaResult\":\"Success\"}"); } }
public async Task<AccountResponse> ForgotPassword(string userName, string url) { var userToReset = await _accountProvider.Find(userName); string code = await _accountProvider.GeneratePasswordResetToken(userToReset.Id); var callbackUrl = string.Format("{0}{1}/{2}?userId={3}&code={4}", url, "Account", "ResetPassword", userToReset.Id, UtilityHelper.EncodeUrlCode(code)); IProcessEmail processEmail = new ProcessEmail(userName); processEmail.SendPasswordResetEmail(userToReset, callbackUrl); return new AccountResponse { Success = true, }; }
public async Task<AccountResponse> RequestEmailConfirmation(string userName, string url) { var recipientUser = await _accountProvider.Find(userName); string emailConfirmationToken = await _accountProvider.GenerateEmailConfirmationToken(recipientUser.Id); var callback = string.Format("{0}{1}/{2}?userId={3}&code={4}", url, "Account", "ConfirmEmail", recipientUser.Id, UtilityHelper.EncodeUrlCode(emailConfirmationToken)); IProcessEmail processEmail = new ProcessEmail(userName); processEmail.SendEmailConfirmationEmail(recipientUser, callback); return new AccountResponse { Success = true, }; }