diff --git a/api/controllers/ViewController.js b/api/controllers/ViewController.js index 920db3f2..779a151f 100644 --- a/api/controllers/ViewController.js +++ b/api/controllers/ViewController.js @@ -4,7 +4,6 @@ */ const Boom = require('@hapi/boom'); const Hoek = require('@hapi/hoek'); -const Recaptcha = require('recaptcha2'); const Client = require('../models/Client'); const User = require('../models/User'); const EmailService = require('../services/EmailService'); @@ -17,8 +16,9 @@ const config = require('../../config/env'); const { logger } = config; function _getRegisterLink(args) { + // Registrations disabled. No register page link. const params = HelperService.getOauthParams(args); - let registerLink = '/register'; + let registerLink = '/'; if (params) { registerLink += `?${params}`; } @@ -27,11 +27,11 @@ function _getRegisterLink(args) { function _getPasswordLink(args) { const params = HelperService.getOauthParams(args); - let registerLink = '/password'; + let passwordLink = '/password'; if (params) { - registerLink += `?${params}`; + passwordLink += `?${params}`; } - return registerLink; + return passwordLink; } function _buildRequestUrl(request, url) { @@ -216,125 +216,25 @@ module.exports = { }, register(request, reply) { - const requestUrl = _buildRequestUrl(request, 'verify'); - return reply.view('register', { - title: 'Register a Humanitarian ID account', - formEmail: '', - formGivenName: '', - formFamilyName: '', - requestUrl, - recaptcha_site_key: process.env.RECAPTCHA_PUBLIC_KEY, + // Early return, no registration allowed. + return reply.view('login', { + alert: { + type: 'error', + message: 'No new registrations are accepted.', + }, + query: request.query, }); }, async registerPost(request, reply) { - // Check recaptcha - const recaptcha = new Recaptcha({ - siteKey: process.env.RECAPTCHA_PUBLIC_KEY, - secretKey: process.env.RECAPTCHA_PRIVATE_KEY, + // Early return, no registration allowed. + return reply.view('login', { + alert: { + type: 'error', + message: 'No new registrations are accepted.', + }, + query: request.query, }); - const registerLink = _getRegisterLink(request.payload); - const passwordLink = _getPasswordLink(request.payload); - let requestUrl = _buildRequestUrl(request, 'verify'); - - // Validate the visitor's response to reCAPTCHA challenge. - try { - await recaptcha.validate(request.payload['g-recaptcha-response']); - } catch (err) { - const errorType = 'RECAPTCHA'; - - logger.warn( - '[ViewController->registerPost] Failure during reCAPTCHA validation.', - { - request, - security: true, - fail: true, - stack_trace: err.stack, - error_type: errorType, - }, - ); - - return reply.view('register', { - alert: { - type: 'error', - message: ` -
Our system detected your registration attempt as spam. We apologize for the inconvenience.
-For more information on why this problem may be occurring, please see our FAQs
- `, - error_type: errorType, - }, - formEmail: request.payload.email, - formGivenName: request.payload.given_name, - formFamilyName: request.payload.family_name, - query: request.query, - registerLink, - passwordLink, - requestUrl, - recaptcha_site_key: process.env.RECAPTCHA_PUBLIC_KEY, - }); - } - - // reCAPTCHA validation was successful. Proceed. - try { - // Attempt to create a new HID account. - await UserController.create(request); - - // Render login form with success message. - return reply.view('login', { - alert: { - type: 'status', - message: 'Thank you for creating an account. You will soon receive a confirmation email to confirm your account.', - }, - query: request.query, - registerLink, - passwordLink, - }); - } catch (err) { - // Check if we have an error worth telling the user about. - const errorMessage = err.output && err.output.payload && err.output.payload.message; - let userMessage = 'There is an error in your registration. You may have already registered. If so, simply reset your password at https://auth.humanitarian.id/password.'; - - // If the error says the email already exists, we'll redirect to login. - if (errorMessage && errorMessage.indexOf('is already registered') !== -1) { - userMessage = 'That email address is already registered. Please login, or if you\'ve forgotten your password, reset using the link below.'; - - return reply.view('login', { - alert: { - type: 'error', - message: userMessage, - }, - query: request.query, - registerLink, - passwordLink, - }); - } - - // Check the error for a few special cases to provide better user feedback. - // All of these will render the registration form. - if (errorMessage && errorMessage.indexOf('password does not meet') !== -1) { - userMessage = 'Your password was not strong enough. Please check the requirements and try again.'; - } - if (errorMessage && errorMessage.indexOf('fields do not match') !== -1) { - userMessage = 'Your password fields did not match. Please try again and carefully confirm the password.'; - } - - // Add a domain from the allow-list. - requestUrl = _buildRequestUrl(request, 'register'); - - // Render registration form. - return reply.view('register', { - alert: { - type: 'warning', - message: userMessage, - }, - query: request.query, - formEmail: request.payload.email, - formGivenName: request.payload.given_name, - formFamilyName: request.payload.family_name, - requestUrl, - recaptcha_site_key: process.env.RECAPTCHA_PUBLIC_KEY, - }); - } }, async verify(request, reply) { diff --git a/config/routes.js b/config/routes.js index d6d1b882..49c827bb 100644 --- a/config/routes.js +++ b/config/routes.js @@ -26,7 +26,8 @@ module.exports = [ * Public-facing pages * * None of these routes require a session. Account setup/recovery actions are - * all included here: registration, verify, password reset, API docs, etc. + * all included here: verify, password reset, API docs, etc. + * Registration is disabled - https://humanitarian.atlassian.net/browse/HID-2438 */ { method: 'GET', @@ -46,6 +47,7 @@ module.exports = [ }, }, + /* { method: 'GET', path: '/register', @@ -63,6 +65,7 @@ module.exports = [ auth: false, }, }, + */ { method: 'GET', diff --git a/config/web.js b/config/web.js index 25833f89..09628580 100644 --- a/config/web.js +++ b/config/web.js @@ -130,7 +130,6 @@ const config = { '/', '/login', '/oauth/authorize', - '/register', '/verify', '/password', '/new-password', diff --git a/templates/login.html b/templates/login.html index da2ee2da..c8c3f1eb 100644 --- a/templates/login.html +++ b/templates/login.html @@ -49,7 +49,6 @@Register a new Humanitarian ID Account
diff --git a/templates/register.html b/templates/register.html index 996ee42a..20141503 100644 --- a/templates/register.html +++ b/templates/register.html @@ -4,61 +4,25 @@