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); }
/// <summary> /// Logs the user in to the API /// </summary> public LoginUserResponse ExecuteLoginUser(LoginUserQueryParam loginParams) { 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.LoginUser(loginParams); if (!loginResult.Success) { throw new UseCaseException() { UserErrorMessage = loginResult.ResponseMessage == null ? "Could not login as the email and/or password was invalid" : loginResult.ResponseMessage } } ; var user = _usersGateway.GetUserByEmail(loginParams.Email, UserStatus.Active); var loginResponse = CreateLoginSession(loginParams, user); return(loginResponse); }
public UserResponse AdminExecute(AdminCreateUserRequest createRequestData) { UserResponse response = null; string subId; // check for currently active user with the same email address (prevents 2 active // users with the same email address in the database which can cause problems // elsewhere, e.g. 'login user') var user = _usersGateway.GetUserByEmail(createRequestData.Email, UserStatus.Active); if (user != null) { throw new UseCaseException() { UserErrorMessage = "An active user with the supplied email address is already registered" } } ; try { subId = _authGateway.AdminCreateUser(createRequestData); } catch (AmazonCognitoIdentityProviderException e) { LoggingHandler.LogError(e.Message); LoggingHandler.LogError(e.StackTrace); return(null); } if (subId != null) { var userDomain = _usersGateway.AddUser(createRequestData, subId); if (userDomain != null) { response = userDomain.ToResponse(); } response.SetPasswordRequired = true; } return(response); }