diff --git a/.env.example b/.env.example index c4f3a4d98..5bcb4ac9e 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,12 @@ SECRET_KEY_BASE= # Force all access to the app over SSL, default is set to false FORCE_SSL= +# This lets you control new sign ups on your chatwoot installation +# true : default option, allows sign ups +# false : disables all the end points related to sign ups +# api_only: disables the UI for signup, but you can create sign ups via the account apis +ENABLE_ACCOUNT_SIGNUP= + #redis config REDIS_URL=redis://redis:6379 # If you are using docker-compose, set this variable's value to be any string, diff --git a/app/controllers/api/v1/accounts_controller.rb b/app/controllers/api/v1/accounts_controller.rb index 0bbf2f67f..96e488231 100644 --- a/app/controllers/api/v1/accounts_controller.rb +++ b/app/controllers/api/v1/accounts_controller.rb @@ -4,6 +4,7 @@ class Api::V1::AccountsController < Api::BaseController skip_before_action :verify_authenticity_token, only: [:create] skip_before_action :authenticate_user!, :set_current_user, :check_subscription, :handle_with_exception, only: [:create], raise: false + before_action :check_signup_enabled rescue_from CustomExceptions::Account::InvalidEmail, CustomExceptions::Account::UserExists, @@ -30,4 +31,8 @@ class Api::V1::AccountsController < Api::BaseController def account_params params.permit(:account_name, :email) end + + def check_signup_enabled + raise ActionController::RoutingError, 'Not Found' if ENV.fetch('ENABLE_ACCOUNT_SIGNUP', true) == 'false' + end end diff --git a/app/javascript/dashboard/routes/auth/auth.routes.js b/app/javascript/dashboard/routes/auth/auth.routes.js index 49ee74c08..abd8d2763 100644 --- a/app/javascript/dashboard/routes/auth/auth.routes.js +++ b/app/javascript/dashboard/routes/auth/auth.routes.js @@ -36,6 +36,7 @@ export default { path: 'signup', name: 'auth_signup', component: Signup, + meta: { requireSignupEnabled: true }, }, { path: 'reset/password', diff --git a/app/javascript/dashboard/routes/index.js b/app/javascript/dashboard/routes/index.js index 924c000bc..006096631 100644 --- a/app/javascript/dashboard/routes/index.js +++ b/app/javascript/dashboard/routes/index.js @@ -97,6 +97,14 @@ export const validateAuthenticateRoutePermission = (to, from, next) => { }; const validateRouteAccess = (to, from, next) => { + if ( + window.chatwootConfig.signupEnabled !== 'true' && + to.meta && + to.meta.requireSignupEnabled + ) { + next(frontendURL('dashboard')); + } + if (authIgnoreRoutes.includes(to.name)) { return next(); } diff --git a/app/javascript/dashboard/routes/login/Login.vue b/app/javascript/dashboard/routes/login/Login.vue index a9c680250..9d54a2315 100644 --- a/app/javascript/dashboard/routes/login/Login.vue +++ b/app/javascript/dashboard/routes/login/Login.vue @@ -1,24 +1,44 @@