diff --git a/jest.config.js b/jest.config.js index 93654b7..6711027 100644 --- a/jest.config.js +++ b/jest.config.js @@ -30,8 +30,6 @@ module.exports = { '/src/server/router.js', '/src/server/index.js', '/src/server/localisation.js', - '/src/server/login/index.js', - '/src/server/login/controller.js', '/src/config/nunjucks/context/index.js', '/src/config/nunjucks/index.js', '/webpack/universalModuleDefinition', diff --git a/src/server/common/helpers/errors.js b/src/server/common/helpers/errors.js index 63955da..f1ce37f 100644 --- a/src/server/common/helpers/errors.js +++ b/src/server/common/helpers/errors.js @@ -24,6 +24,7 @@ function catchAll(request, h) { return h.continue } + request.logger.error(response) request.logger.error(response?.stack) // return response.output return h.redirect( diff --git a/src/server/home/index.js b/src/server/home/index.js index de577de..cf04c52 100644 --- a/src/server/home/index.js +++ b/src/server/home/index.js @@ -7,7 +7,7 @@ const home = { server.route([ { method: 'GET', - path: '/home', + path: '/', ...homeController } ]) diff --git a/src/server/home/index.test.js b/src/server/home/index.test.js index bb3f6d8..e96ceec 100644 --- a/src/server/home/index.test.js +++ b/src/server/home/index.test.js @@ -13,7 +13,7 @@ describe('home plugin', () => { test('should register the /home route', () => { const routes = server.table() const homeRoute = routes.find( - (route) => route.path === '/home' && route.method === 'get' + (route) => route.path === '/' && route.method === 'get' ) expect(homeRoute).toBeDefined() diff --git a/src/server/index.js b/src/server/index.js index cc3a03c..a632ce1 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -7,10 +7,8 @@ import { router } from './router' import { requestLogger } from '~/src/server/common/helpers/logging/request-logger' import { catchAll } from '~/src/server/common/helpers/errors' import { secureContext } from '~/src/server/common/helpers/secure-context' -import hapiCookie from '@hapi/cookie' const isProduction = config.get('isProduction') -const cookiePassword = config.get('cookiePassword') async function createServer() { const server = hapi.server({ @@ -50,28 +48,6 @@ async function createServer() { if (isProduction) { await server.register(secureContext) } - await server.register([hapiCookie]) - // cookie based strategy setup - server.auth.strategy('login', 'cookie', { - cookie: { - name: 'phi-cookie', - path: '/', - password: cookiePassword, - isSecure: isProduction - }, - redirectTo: '/', - keepAlive: true - // to validate cookie content on each request and returns boolean(isauthenticated/not) - // validate: async (request, session) => { - // if (session.password === config.get('phiPassword')) { - // return { isValid: true } - // } else { - // return { isValid: true } - // } - // } - }) - // register with every route to use correct credentials - server.auth.default({ strategy: 'login', mode: 'required' }) await server.register(router) await server.register(nunjucksConfig) diff --git a/src/server/locales/login/en_cy.json b/src/server/locales/login/en_cy.json deleted file mode 100644 index 5489ce5..0000000 --- a/src/server/locales/login/en_cy.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "govukcaption": "Arweiniad", - "govukheading": "Gwiriwch wybodaeth iechyd planhigion a rheolau mewnforio", - "govukbodytitle": "Defnyddiwch y gwasanaeth hwn i ddod o hyd i wybodaeth am y risgiau o bla neu glefyd sy'n gysylltiedig â mewnforio planhigyn i Brydain Fawr (Cymru, Lloegr a'r Alban).", - "buttonText": "Dechreuwch nawr", - "publishedSection": { - "publishedOtherText": { - "t1": "Oddi wrth:", - "t2": "a" - }, - "publishedDates": { - "text1": "Wedi'i gyhoeddi ar 14 Rhagfyr 2023", - "text2": "Wedi ei ddiweddaru ddiwetha' 23 Chwefror 2024 —" - } - }, - "appliesToSection": { - "appliesToText": "Yn berthnasol i\r\n Lloegr, yr Alban a Chymru" - }, - "textBeforeStartNowSection": { - "paragraphText1": "Defnyddiwch y gwasanaeth hwn i gael gwybod:", - "bulletText1": "y rheolau diweddaraf ar gyfer mewnforio planhigion neu gynhyrchion planhigion penodol", - "bulletText2": "a allai planhigyn gario plâu a chlefydau y mae angen adrodd amdanynt", - "bulletText3": "gwybodaeth gyfredol am blâu a chlefydau planhigion anfrodorol\r\n sy'n risg i Brydain Fawr" - }, - "textAfterStartNowSection": { - "headerText": "Cyn i chi ddechrau", - "paragraphText1": "Bydd angen enw'r planhigyn, y cynnyrch planhigyn, y pla neu'r afiechyd arnoch i ddod o hyd i wybodaeth am blanhigion\r\niechyd\r\n.", - "paragraphText2": "Gallwch ddefnyddio:", - "paragraphText3": "Y gwasanaeth hwn:", - "bulletText1": "yr enw gwyddonol neu unrhyw gyfystyron", - "bulletText2": "enw cyffredin mewn rhai achosion", - "bulletText3": "nad yw'n darparu gwybodaeth fasnachol am allforio planhigion neu gynhyrchion planhigion", - "bulletText4": "nid yw'n wasanaeth adnabod pla neu afiechyd", - "bulletText5": "nid oes ganddo wybodaeth am blâu a chlefydau sy'n frodorol i Brydain Fawr" - }, - "relatedContentSection": { - "headerText": "Cynnwys cysylltiedig" - }, - "getHelpSection": { - "titleText": "Cael help gyda'r gwasanaeth hwn", - "supportUrl": { - "text": "os oes gennych unrhyw ymholiadau neu os oes angen cymorth technegol arnoch, e-bostiwch" - }, - "betabannertext1": "Mae hwn yn wasanaeth newydd - eich", - "betabannertext2": "bydd yn ein helpu i'w wella.", - "betaText": "Beta" - } -} diff --git a/src/server/locales/login/en_gb.json b/src/server/locales/login/en_gb.json deleted file mode 100644 index deb6550..0000000 --- a/src/server/locales/login/en_gb.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "govukcaption": "Guidance", - "govukheading": "Check plant health information and import rules", - "govukbodytitle": "Use this service to find information on the pest or disease risks of importing a plant, plant product or seeds to Great Britain (England, Scotland and Wales).", - "buttonText": "Start now", - "publishedSection": { - "publishedOtherText": { - "t1": "From:", - "t2": "and" - }, - "publishedDates": { - "text1": "Published 14 December 2023", - "text2": "Last updated 23 February 2024 —" - } - }, - "appliesToSection": { - "appliesToText": "Applies to\r\n England, Scotland and Wales" - }, - "textBeforeStartNowSection": { - "paragraphText1": "Use this service to find out:", - "bulletText1": "the latest rules for importing particular plants or plant products", - "bulletText2": "if a plant could carry pests and diseases that need reporting", - "bulletText3": "current information on non-native plants pests and diseases\r\n that are a risk to Great Britain" - }, - "textAfterStartNowSection": { - "headerText": "Before you start", - "paragraphText1": "You'll need the name of either the plant, plant product, pest or disease to find plant\r\n health\r\n information.", - "paragraphText2": "You can use:", - "paragraphText3": "This service:", - "bulletText1": "the scientific name or any synonyms", - "bulletText2": "a common name in some cases", - "bulletText3": "does not provide trade information about exporting plants or plant products", - "bulletText4": "it is not a pest or disease identification service", - "bulletText5": "does not have information about pests and diseases native to Great Britain" - }, - "relatedContentSection": { - "headerText": "Related content" - }, - "getHelpSection": { - "titleText": "Get help with this service", - "supportUrl": { - "text": "If you have any queries or you need technical support, email" - }, - "betabannertext1": "This is a new service - your", - "betabannertext2": "will help us to improve it.", - "betaText": "Beta" - } -} diff --git a/src/server/login/controller.js b/src/server/login/controller.js deleted file mode 100644 index d942d59..0000000 --- a/src/server/login/controller.js +++ /dev/null @@ -1,53 +0,0 @@ -import { config } from '~/src/config' -const password = config.get('phiPassword') -const loginController = { - handler: (request, h) => { - if (request.auth.isAuthenticated) { - return h.redirect('/home') - } else { - const errors = request.yar.get('errors') - const errorMessage = request.yar.get('errorMessage') - request.yar.set('errors', null) - request.yar.set('errorMessage', null) - return h.view('login/index', { - pageTitle: 'Check plant health information and import rules — GOV.UK', - heading: 'Login Page', - page: 'home', - serviceName: '', - errors: errors?.errors, - errorMessage: errorMessage?.errorMessage - }) - } - } -} - -const authController = { - handler: (request, h) => { - if (request.payload.password === password) { - // once user loggedin , set the cookie with user data and send back cookie with authentication - // this info will also be validated in serverside using validate function - request.cookieAuth.set({ password: request.payload.password }) - return h.redirect('/home') - } else { - request.yar.set('errors', { - errors: { - titleText: 'There is a problem', - errorList: [ - { - text: 'The password is not correct', - href: '#password' - } - ] - } - }) - request.yar.set('errorMessage', { - errorMessage: { - text: 'The password is not correct' - } - }) - return h.redirect('/') - } - } -} - -export { loginController, authController } diff --git a/src/server/login/index.js b/src/server/login/index.js deleted file mode 100644 index 2c5ecc7..0000000 --- a/src/server/login/index.js +++ /dev/null @@ -1,33 +0,0 @@ -import { loginController, authController } from '~/src/server/login/controller' - -const login = { - plugin: { - name: 'login', - register: async (server) => { - server.route([ - { - method: 'GET', - path: '/', - ...loginController, - options: { auth: { mode: 'try' } } // access login page without cookie set , hapi will try to authenticate the user, if fails, the reoute can still be accessed - }, - { - method: 'POST', - path: '/', - ...authController, - options: { auth: { mode: 'try' } } - }, - { - method: 'GET', - path: '/logout', - handler: (request, h) => { - request.cookieAuth.clear() - return h.redirect('/') - } - } - ]) - } - } -} - -export { login } diff --git a/src/server/login/index.njk b/src/server/login/index.njk deleted file mode 100644 index a4cb448..0000000 --- a/src/server/login/index.njk +++ /dev/null @@ -1,46 +0,0 @@ -{% extends 'layouts/page.njk' %} -{% from "govuk/components/button/macro.njk" import govukButton %} -{% from "govuk/components/input/macro.njk" import govukInput %} - {% from "govuk/components/error-summary/macro.njk" import govukErrorSummary %} -{% block pageTitle %} - Sign in -{% endblock %} - -{% block content %} - {% call appPageBody() %} -
-
- {% if errors %} -
-
- {{ govukErrorSummary(errors) }} -
-
- {% endif %} -

- Sign in - To Check plant health information and import rules - -

-

- You should only continue if you have been invited to. -

-
- {{ govukInput({ - label: { - text: "Password", - classes: "govuk-label" - }, - classes: "govuk-!-width-one-third", - id: "password", - name: "password", - type: "password", - errorMessage:errorMessage - }) }} - {{ govukButton({ - text: "Continue" - }) }} -
-
-
- {% endcall %} -{% endblock %} \ No newline at end of file diff --git a/src/server/router.js b/src/server/router.js index 4857747..f84dda8 100644 --- a/src/server/router.js +++ b/src/server/router.js @@ -11,11 +11,9 @@ import { formatPage } from '~/src/server/plant-health/format' import { serveStaticFiles } from '~/src/server/common/helpers/serve-static-files' import { pestSearchPage } from '~/src/server/plant-health/pest-search' import { problemWithService } from '~/src/server/check-plant-health-information-and-import-rules/problem-with-service' - import { pestDetailsPage } from '~/src/server/plant-health/pest-details' import { search } from '~/src/api/search' import { config } from '~/src/config' -import { login } from '~/src/server/login' import { accessibilityStatement } from '~/src/server/accessibility' import { CookiesPage } from '~/src/server/cookies' @@ -47,7 +45,6 @@ const router = { pestSearchPage, pestDetailsPage, CookiesPage, - login, problemWithService, accessibilityStatement, serveStaticFiles