コード例 #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);
        }
コード例 #2
0
        public void Execute(int userId)
        {
            var user = _usersGateway.GetUserById(userId);

            if (user == null)
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = $"A user with the provided ID={userId} does not exist"
                      }
            }
            ;

            if (_authenticateGateway.DeleteUser(user.Email))
            {
                _sessionsGateway.RemoveSessions(user.Id);
                _userOrganisationGateway.DeleteUserOrganisationLink(user.Id);
                _usersGateway.ClearUserRoles(user.Id);
                _usersGateway.SetUserStatus(user, UserStatus.Deleted);
            }
        }
    }
コード例 #3
0
        public LoginUserResponse ExecuteFirstLogin(ResetPasswordQueryParams loginParams, string ipAddress)
        {
            if (string.IsNullOrWhiteSpace(loginParams.Email))
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = "Could not login as the email address was invalid"
                      }
            }
            ;

            if (string.IsNullOrWhiteSpace(loginParams.Password))
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = "Could not login as the password was invalid"
                      }
            }
            ;
            var loginResult = _authenticateGateway.ChangePassword(loginParams);

            if (loginResult == null)
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = "Could not login as the email and/or password was invalid"
                      }
            }
            ;
            loginResult.IpAddress = ipAddress;
            var user = _usersGateway.GetUserByEmail(loginParams.Email, UserStatus.Invited);

            _usersGateway.SetUserStatus(user, UserStatus.Active);
            var loginResponse = CreateLoginSession(loginResult, user);

            return(loginResponse);
        }

        LoginUserResponse CreateLoginSession(LoginUserQueryParam loginParams, UserDomain user)
        {
            var timestamp = DateTime.UtcNow;
            var sessionId = Guid.NewGuid().ToString();

            LoggingHandler.LogInfo(loginParams.IpAddress);
            LoggingHandler.LogInfo(user.Id.ToString());

            Session session = new Session()
            {
                IpAddress    = loginParams.IpAddress,
                CreatedAt    = timestamp,
                LastAccessAt = timestamp,
                UserId       = user.Id,
                Payload      = sessionId,
            };

            _sessionsGateway.AddSession(session);

            return(new LoginUserResponse()
            {
                AccessToken = sessionId
            });
        }