Skip to content

Commit

Permalink
GAP-1965 - Adds error handling for privacy policy page.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiramarstonTCO committed Jul 14, 2023
1 parent 05dd48e commit 8c5973b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gov.cabinetofice.gapuserservice.dto;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class PrivacyPolicyDto {
@NotBlank(message = "You need to agree to the privacy policy to continue.")
private String acceptPrivacyPolicy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import gov.cabinetofice.gapuserservice.config.ApplicationConfigProperties;
import gov.cabinetofice.gapuserservice.dto.OneLoginUserInfoDto;
import gov.cabinetofice.gapuserservice.dto.PrivacyPolicyDto;
import gov.cabinetofice.gapuserservice.model.User;
import gov.cabinetofice.gapuserservice.service.OneLoginService;
import gov.cabinetofice.gapuserservice.service.jwt.impl.CustomJwtServiceImpl;
import gov.cabinetofice.gapuserservice.util.WebUtil;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.util.WebUtils;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -107,11 +107,22 @@ public RedirectView redirectAfterLogin(final @CookieValue(name = REDIRECT_URL_CO
}

@GetMapping("/privacy-policy")
public ModelAndView showNoticePage() {
return new ModelAndView(PRIVACY_POLICY_PAGE_VIEW)
.addObject("loginUrl", oneLoginBaseUrl);
public ModelAndView showPrivacyPolicyPage(final @ModelAttribute("privacyPolicy") PrivacyPolicyDto privacyPolicyDto) {
return new ModelAndView(PRIVACY_POLICY_PAGE_VIEW);
}

@PostMapping("/privacy-policy")
public ModelAndView showPrivacyPolicyPage(final @Valid @ModelAttribute("privacyPolicy") PrivacyPolicyDto privacyPolicyDto, final BindingResult result) {

if (result.hasErrors()) {
return new ModelAndView(PRIVACY_POLICY_PAGE_VIEW);
}

//TODO: GAP-1972 will implement correct redirect
return new ModelAndView( "redirect:/register/success");
}


private Cookie generateCustomJwtCookie(final OneLoginUserInfoDto userInfo) {
final Map<String, String> claims = new HashMap<>();
claims.put("email", userInfo.getEmail());
Expand Down
75 changes: 45 additions & 30 deletions src/main/resources/templates/privacy-policy.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,63 @@
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">


<link rel="stylesheet" th:href="@{/webjars/govuk-frontend/4.5.0/govuk-frontend.min.css}" />
<link rel="stylesheet" th:href="@{/webjars/govuk-frontend/4.5.0/govuk-frontend.min.css}"/>
</head>

<body class="govuk-template__body">
<div th:replace="~{fragments/header :: header}"></div>

<div class="govuk-width-container" >
<div class="govuk-width-container">
<a th:href="${homePageUrl}" class="govuk-back-link">Back</a>

<main class="govuk-main-wrapper" id="main-content" role="main">
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l">Do you accept our privacy policy?</h1>
<p class="govuk-body">
Before you can continue, you need to read and agree to the
<a href="https://www.find-government-grants.service.gov.uk/info/privacy" target="_blank">
Find a grant privacy policy (opens in a new tab)</a>
</p>
<p>
<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input type="checkbox"
th:id="privacyPolicy"
th:name="privacyPolicy"
th:checked="*{privacyPolicy == 'yes'}"
th:value="yes"
class="govuk-checkboxes__input"
/>

<label class="govuk-label govuk-checkboxes__label" th:for="privacyPolicy">
Yes, I have read and agree to the Find a grant privacy policy
</label>
</div>
</div>
</p>
<form method="post" th:action="@{/v2/privacy-policy}" th:object="${privacyPolicy}" novalidate>
<div th:classappend="${#fields.hasErrors('acceptPrivacyPolicy') ? 'govuk-form-group--error' : ''}">
<h1 class="govuk-heading-l">Do you accept our privacy policy?</h1>
<p class="govuk-body">
Before you can continue, you need to read and agree to the
<a href="https://www.find-government-grants.service.gov.uk/info/privacy" target="_blank">
Find a grant privacy policy (opens in a new tab).</a>
</p>

<div class="govuk-form-group">
<p th:id="privacy-policy-error"
th:class="govuk-error-message"
data-cy="cy-email-input-validation-error-details"
data-testid="error-message-test-id"
th:errors="*{acceptPrivacyPolicy}"
>
<span className="govuk-visually-hidden">Error: </span>
</p>

<div class="govuk-checkboxes" data-module="govuk-checkboxes">
<div class="govuk-checkboxes__item">
<input type="checkbox"
th:id="acceptPrivacyPolicy"
th:name="acceptPrivacyPolicy"
th:checked="*{acceptPrivacyPolicy == 'yes'}"
th:value="yes"
class="govuk-checkboxes__input"
/>

<label class="govuk-label govuk-checkboxes__label" th:for="acceptPrivacyPolicy">
Yes, I have read and agree to the Find a grant privacy policy
</label>
</div>
</div>

</div>

</div>
<div class="govuk-form-group">
<button class="govuk-button" data-module="govuk-button">
Continue
</button>
</div>

<a th:href="${loginUrl}" role="button" draggable="false" class="govuk-button" data-module="govuk-button">
Continue
</a>
</form>
</div>
</div>
</main>
Expand Down

0 comments on commit 8c5973b

Please sign in to comment.