Skip to content
Snippets Groups Projects
Unverified Commit 54d1c2f3 authored by Ahmad Farhat's avatar Ahmad Farhat Committed by GitHub
Browse files

Make SMTP not required (#4749)

* Make SMTP not required

* quick fix
parent 5ba77545
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ module Api
# POST /api/v1/users.json
# Creates and saves a new user record in the database with the provided parameters
def create
smtp_enabled = ENV['SMTP_SERVER'].present?
# Check if this is an admin creating a user
admin_create = current_user && PermissionsChecker.new(current_user:, permission_names: 'ManageUsers', current_provider:).call
......@@ -37,6 +38,8 @@ module Api
user = UserCreator.new(user_params: create_user_params.except(:invite_token), provider: current_provider, role: default_role).call
user.verify! unless smtp_enabled
# TODO: Add proper error logging for non-verified token hcaptcha
if !admin_create && hcaptcha_enabled? && !verify_hcaptcha(response: params[:token])
return render_error errors: Rails.configuration.custom_error_msgs[:hcaptcha_invalid]
......@@ -46,10 +49,12 @@ module Api
user.pending! if !admin_create && registration_method == SiteSetting::REGISTRATION_METHODS[:approval]
if user.save
if smtp_enabled
token = user.generate_activation_token!
UserMailer.with(user:, expires_in: User::ACTIVATION_TOKEN_VALIDITY_PERIOD.from_now,
activation_url: activate_account_url(token), base_url: request.base_url,
provider: current_provider).activate_account_email.deliver_later
end
create_default_room(user)
......
......@@ -20,23 +20,23 @@ DATABASE_URL=
# E.g. redis://redis:6379
REDIS_URL=
### OPTIONAL ENV VARS
### SMTP CONFIGURATION
# Emails are required for the basic features of Greenlight to function.
# Please refer to your SMTP provider to get the values for the variables below
SMTP_SENDER_EMAIL=
SMTP_SENDER_NAME=
SMTP_SERVER=
SMTP_PORT=
SMTP_DOMAIN=
SMTP_USERNAME=
SMTP_PASSWORD=
SMTP_AUTH=
SMTP_STARTTLS_AUTO=
SMTP_STARTTLS=
SMTP_TLS=
SMTP_SSL_VERIFY=
### OPTIONAL ENV VARS
#SMTP_SENDER_EMAIL=
#SMTP_SENDER_NAME=
#SMTP_SERVER=
#SMTP_PORT=
#SMTP_DOMAIN=
#SMTP_USERNAME=
#SMTP_PASSWORD=
#SMTP_AUTH=
#SMTP_STARTTLS_AUTO=true
#SMTP_STARTTLS=false
#SMTP_TLS=false
#SMTP_SSL_VERIFY=true
### EXTERNAL AUTHENTICATION METHODS
#
......
......@@ -8,6 +8,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
let(:fake_setting_getter) { instance_double(SettingGetter) }
before do
ENV['SMTP_SERVER'] = 'test.com'
request.headers['ACCEPT'] = 'application/json'
end
......@@ -63,6 +64,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end
context 'activation' do
context 'SMTP enabled' do
it 'generates an activation token for the user' do
freeze_time
......@@ -83,6 +85,21 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end
end
context 'SMTP disabled' do
before do
ENV['SMTP_SERVER'] = ''
end
it 'marks the user as verified and signs them in' do
post :create, params: user_params
user = User.find_by email: user_params[:user][:email]
expect(user).to be_verified
expect(session[:session_token]).to eq(user.session_token)
end
end
end
context 'Admin creation' do
before { sign_in_user(user) }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment