Пример #1
0
        public UserResponse Execute(UserConfirmRequest confirmRequest)
        {
            var response = new UserResponse();

            if (_authenticateGateway.ConfirmSignup(confirmRequest))
            {
                var user = _usersGateway.GetUserByEmail(confirmRequest.Email, UserStatus.Invited);

                if (user == null)
                {
                    user = _usersGateway.GetUserByEmail(confirmRequest.Email, UserStatus.Unverified);

                    if (user == null)
                    {
                        // could not find user in either of the required states to confirm registration (invited/unverified)
                        throw new UseCaseException()
                              {
                                  UserErrorMessage = "User with the supplied email address not found in the required state of invited or unverified"
                              };
                    }
                }
                _usersGateway.SetDefaultRole(user);
                _usersGateway.SetUserStatus(user, UserStatus.Active);
                response = user.ToResponse();
            }
            else
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = "Could not validate user registration on the authentication gateway"
                      };
            }

            return(response);
        }
        public IActionResult ConfirmUser([FromBody] UserConfirmRequest userConfirmRequest)
        {
            UserResponse response;

            if (!userConfirmRequest.IsValid())
            {
                return(BadRequest("Invalid details provided"));
            }

            try
            {
                userConfirmRequest.IpAddress = HttpContext.Connection.RemoteIpAddress.ToString();
                response = _confirmUserUseCase.Execute(userConfirmRequest);
            }
            catch (UseCaseException e)
            {
                return(BadRequest(e));
            }

            return(Accepted(response));
        }
Пример #3
0
        public bool ConfirmSignup(UserConfirmRequest confirmRequest)
        {
            ConfirmSignUpRequest signUpRequest = new ConfirmSignUpRequest
            {
                ClientId         = _connectionInfo.ClientId,
                Username         = confirmRequest.Email,
                ConfirmationCode = confirmRequest.Code
            };

            try
            {
                ConfirmSignUpResponse response = _provider.ConfirmSignUpAsync(signUpRequest).Result;
                return(response.HttpStatusCode == HttpStatusCode.OK);
            }
            catch (AggregateException e)
            {
                if (e.InnerException != null)
                {
                    throw new UseCaseException()
                          {
                              UserErrorMessage = e.Message
                          }
                }
                ;

                throw new UseCaseException()
                      {
                          UserErrorMessage = e.Message, DevErrorMessage = e.ToString()
                      };
            }
            catch (Exception e)
            {
                LoggingHandler.LogError(e.Message);
                LoggingHandler.LogError(e.StackTrace);
                throw;
            }
        }
 public static bool IsValid(this UserConfirmRequest confirmRequest)
 {
     return((!string.IsNullOrWhiteSpace(confirmRequest.Email)) &&
            (!string.IsNullOrWhiteSpace(confirmRequest.Code)));
 }