예제 #1
0
        public async Task <RegistrationResponse> RegisterUser([FromBody] RegisterUserRequest userRequest)
        {
            _thimbleLogger.Log(userRequest.UserId, "useraccount.registration.started");
            await _contactInformationDynamoClient.RegisterUser(userRequest);

            return(new RegistrationResponse {
                UserId = userRequest.UserId
            });
        }
예제 #2
0
        public async Task SendEmail(EmailRequest emailRequest)
        {
            var dynamoClient = _awsService.GetDynamoClient();
            await dynamoClient.PutItemAsync(DynamoConstants.EMAILS_TABLE, new Dictionary <string, AttributeValue>
            {
                { DynamoConstants.UserIdKey, new AttributeValue(emailRequest.UserId) },
                { DynamoConstants.EmailKey, new AttributeValue(emailRequest.Email) },
            });

            _thimbleLogger.Log("messaging.email.stored");
            var sesClient = _awsService.GetSesClient();
            await sesClient.SendEmailAsync(ComposeEmail.Create(DynamoConstants.ThimbleEmail, emailRequest.Email));

            _thimbleLogger.Log("messaging.email.sent");
        }
        public async Task Invoke(HttpContext context, IThimbleLogger thimbleLogger)
        {
            try
            {
                await _next(context);
            }
            catch (Exception ex)
            {
                context.Response.Clear();
                context.Response.StatusCode  = 500;
                context.Response.ContentType = "application/json";

                var responseObject = new ErrorResponse {
                    Message = ex.Message
                };

                if (ex.GetType() == typeof(InvalidEmailOrPasswordException))
                {
                    SetResponse(StaticErrorResponses.Unauthorized, context, responseObject);
                }

                var serializedBody = JsonConvert.SerializeObject(responseObject, Formatting.Indented,
                                                                 new JsonSerializerSettings
                {
                    Formatting         = Formatting.Indented,
                    DateFormatHandling = DateFormatHandling.IsoDateFormat,
                    NullValueHandling  = NullValueHandling.Ignore,
                    ContractResolver   = new CamelCasePropertyNamesContractResolver()
                });
                thimbleLogger.Log(ex, "credentials.error");
                await context.Response.WriteAsync(serializedBody, Encoding.UTF8);
            }
        }
        public async Task <OkResult> StoreAndSendEmail([FromBody] EmailRequest emailRequest)
        {
            _thimbleLogger.Log("messaging.email.started");
            await _emailService.SendEmail(emailRequest);

            return(Ok());
        }
        public async Task <ActionResult> CreatePassword([FromBody] PasswordRequest passwordRequest)
        {
            _thimbleLogger.Log(passwordRequest.UserId, "credentials.registration.started");
            await _credentialsDynamoClient.CreatePassword(passwordRequest);

            _thimbleLogger.Log(passwordRequest.UserId, "credentials.registration.successful");
            return(Created("Thimble.Password", new PasswordResponse {
                UserId = passwordRequest.UserId
            }));
        }