Added variable in .env to enforce certain domains in account registrations (#1589)

Allow REQUIRE_MAIL_DOMAIN to not exist in addition to it being empty

Undo changes in config/locales/de_DE.yml

changed .env variable name to GREENLIGHT_ACCOUNT_HD; allowed only comma and no whitespace as separator

Allow the admin to change email-addresses, just enforce domain on registration

Co-authored-by: Gaja Sophie Peters <gaja.peters@uni-hamburg.de>
Co-authored-by: Ahmad Farhat <ahmad.af.farhat@gmail.com>
This commit is contained in:
EmmyGraugans
2021-06-01 23:11:15 +02:00
committed by GitHub
parent 0181678e1a
commit 505ed05c5a
4 changed files with 18 additions and 0 deletions

View File

@ -39,6 +39,7 @@ class User < ApplicationRecord
format: { without: %r{https?://}i }
validates :provider, presence: true
validate :check_if_email_can_be_blank
validate :check_domain, if: :greenlight_account?, on: :create
validates :email, length: { maximum: 256 }, allow_blank: true,
uniqueness: { case_sensitive: false, scope: :provider },
format: { with: /\A[\w+\-'.]+@[a-z\d\-.]+\.[a-z]+\z/i }
@ -234,6 +235,13 @@ class User < ApplicationRecord
Role.create_default_roles(role_provider) if Role.where(provider: role_provider).count.zero?
end
def check_domain
if Rails.configuration.require_email_domain.any? && !email.end_with?(*Rails.configuration.require_email_domain)
errors.add(:email, I18n.t("errors.messages.domain",
email_domain: Rails.configuration.require_email_domain.join('" ' + I18n.t("modal.login.or") + ' "')))
end
end
def check_if_email_can_be_blank
if email.blank?
if Rails.configuration.loadbalanced_configuration && greenlight_account?