Search in sources :

Example 1 with TermsAndConditions

use of uk.gov.di.authentication.shared.entity.TermsAndConditions in project di-authentication-api by alphagov.

the class DynamoService method updateTermsAndConditions.

@Override
public void updateTermsAndConditions(String email, String version) {
    TermsAndConditions termsAndConditions = new TermsAndConditions(version, LocalDateTime.now(ZoneId.of("UTC")).toString());
    userProfileMapper.save(userProfileMapper.load(UserProfile.class, email.toLowerCase(Locale.ROOT)).setTermsAndConditions(termsAndConditions));
}
Also used : TermsAndConditions(uk.gov.di.authentication.shared.entity.TermsAndConditions)

Example 2 with TermsAndConditions

use of uk.gov.di.authentication.shared.entity.TermsAndConditions in project di-authentication-api by alphagov.

the class SignUpHandler method handleRequestWithUserContext.

@Override
public APIGatewayProxyResponseEvent handleRequestWithUserContext(APIGatewayProxyRequestEvent input, Context context, SignupRequest request, UserContext userContext) {
    attachSessionIdToLogs(userContext.getSession());
    attachLogFieldToLogs(PERSISTENT_SESSION_ID, extractPersistentIdFromHeaders(input.getHeaders()));
    attachLogFieldToLogs(CLIENT_ID, userContext.getClient().map(ClientRegistry::getClientID).orElse("unknown"));
    LOG.info("Received request");
    Optional<ErrorResponse> passwordValidationErrors = ValidationHelper.validatePassword(request.getPassword());
    if (passwordValidationErrors.isEmpty()) {
        if (authenticationService.userExists(request.getEmail())) {
            auditService.submitAuditEvent(FrontendAuditableEvent.CREATE_ACCOUNT_EMAIL_ALREADY_EXISTS, context.getAwsRequestId(), userContext.getSession().getSessionId(), userContext.getClient().map(ClientRegistry::getClientID).orElse(AuditService.UNKNOWN), AuditService.UNKNOWN, request.getEmail(), IpAddressHelper.extractIpAddress(input), AuditService.UNKNOWN, PersistentIdHelper.extractPersistentIdFromHeaders(input.getHeaders()));
            return generateApiGatewayProxyErrorResponse(400, ErrorResponse.ERROR_1009);
        }
        authenticationService.signUp(request.getEmail(), request.getPassword(), new Subject(), new TermsAndConditions(configurationService.getTermsAndConditionsVersion(), LocalDateTime.now(ZoneId.of("UTC")).toString()));
        var consentRequired = ConsentHelper.userHasNotGivenConsent(userContext);
        auditService.submitAuditEvent(FrontendAuditableEvent.CREATE_ACCOUNT, context.getAwsRequestId(), userContext.getSession().getSessionId(), userContext.getClient().map(ClientRegistry::getClientID).orElse(AuditService.UNKNOWN), AuditService.UNKNOWN, request.getEmail(), IpAddressHelper.extractIpAddress(input), AuditService.UNKNOWN, PersistentIdHelper.extractPersistentIdFromHeaders(input.getHeaders()));
        sessionService.save(userContext.getSession().setEmailAddress(request.getEmail()).setNewAccount(NEW));
        LOG.info("Successfully processed request");
        try {
            return generateApiGatewayProxyResponse(200, new SignUpResponse(consentRequired));
        } catch (JsonException e) {
            return generateApiGatewayProxyErrorResponse(400, ErrorResponse.ERROR_1001);
        }
    } else {
        return generateApiGatewayProxyErrorResponse(400, passwordValidationErrors.get());
    }
}
Also used : JsonException(uk.gov.di.authentication.shared.serialization.Json.JsonException) SignUpResponse(uk.gov.di.authentication.frontendapi.entity.SignUpResponse) TermsAndConditions(uk.gov.di.authentication.shared.entity.TermsAndConditions) ClientRegistry(uk.gov.di.authentication.shared.entity.ClientRegistry) Subject(com.nimbusds.oauth2.sdk.id.Subject) ErrorResponse(uk.gov.di.authentication.shared.entity.ErrorResponse) ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse(uk.gov.di.authentication.shared.helpers.ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse)

Example 3 with TermsAndConditions

use of uk.gov.di.authentication.shared.entity.TermsAndConditions in project di-authentication-api by alphagov.

the class LoginHandlerTest method generateUserProfile.

private UserProfile generateUserProfile(String legacySubjectId) {
    LocalDateTime localDateTime = LocalDateTime.now();
    Date currentDateTime = Date.from(localDateTime.atZone(ZoneId.of("UTC")).toInstant());
    return new UserProfile().setEmail(EMAIL).setEmailVerified(true).setPhoneNumber(PHONE_NUMBER).setPhoneNumberVerified(true).setPublicSubjectID(new Subject().getValue()).setSubjectID(new Subject().getValue()).setLegacySubjectID(legacySubjectId).setTermsAndConditions(new TermsAndConditions("1.0", currentDateTime.toString()));
}
Also used : LocalDateTime(java.time.LocalDateTime) TermsAndConditions(uk.gov.di.authentication.shared.entity.TermsAndConditions) UserProfile(uk.gov.di.authentication.shared.entity.UserProfile) Date(java.util.Date) Subject(com.nimbusds.oauth2.sdk.id.Subject)

Example 4 with TermsAndConditions

use of uk.gov.di.authentication.shared.entity.TermsAndConditions in project di-authentication-api by alphagov.

the class UserStoreExtension method signUp.

public String signUp(String email, String password, Subject subject) {
    TermsAndConditions termsAndConditions = new TermsAndConditions("1.0", LocalDateTime.now(ZoneId.of("UTC")).toString());
    dynamoService.signUp(email, password, subject, termsAndConditions);
    return dynamoService.getUserProfileByEmail(email).getPublicSubjectID();
}
Also used : TermsAndConditions(uk.gov.di.authentication.shared.entity.TermsAndConditions)

Aggregations

TermsAndConditions (uk.gov.di.authentication.shared.entity.TermsAndConditions)4 Subject (com.nimbusds.oauth2.sdk.id.Subject)2 LocalDateTime (java.time.LocalDateTime)1 Date (java.util.Date)1 SignUpResponse (uk.gov.di.authentication.frontendapi.entity.SignUpResponse)1 ClientRegistry (uk.gov.di.authentication.shared.entity.ClientRegistry)1 ErrorResponse (uk.gov.di.authentication.shared.entity.ErrorResponse)1 UserProfile (uk.gov.di.authentication.shared.entity.UserProfile)1 ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse (uk.gov.di.authentication.shared.helpers.ApiGatewayResponseHelper.generateApiGatewayProxyErrorResponse)1 JsonException (uk.gov.di.authentication.shared.serialization.Json.JsonException)1