Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ en:
ldap_bind_dn: "LDAP bind dn (needed if LDAP server does not allow anonymous binding)"
ldap_password: "LDAP bind password (needed if LDAP server does not allow anonymous binding)"
ldap_filter: "LDAP filter (for group based authentication)"
ldap_email: "Mail attribute to bind in priority to discourse primary mail"
2 changes: 2 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ plugins:
secret: true
ldap_filter:
default: ''
ldap_email:
default: 'email'
8 changes: 8 additions & 0 deletions lib/ldap_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ def initialize (auth_info)
@email = auth_info[:email]
@username = auth_info[:nickname]
@user = SiteSetting.ldap_lookup_users_by == 'username' ? User.find_by_username(@username) : User.find_by_email(@email)
primary_email = @user.user_emails.find_by(email: @user.email)
if primary_email.present?
primary_email.update!(email: @email)
else
@user.user_emails.update_all(primary: false)
@user.user_emails.create!(email: @email, primary: true)
end
@user.reload
create_user_groups(auth_info[:groups]) unless self.account_exists?
end

Expand Down
10 changes: 10 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def enabled?
end

def after_authenticate(auth_options)
if SiteSetting.ldap_email != 'email'
if not auth_options.extra[:raw_info][SiteSetting.ldap_email].blank?
emails = Array(auth_options.extra[:raw_info][SiteSetting.ldap_email])
.select { |email| email.match?(/\A[^@\s]+@[^@\s]+\z/) }
if not emails.empty?
auth_options.info[:email] = emails.first()
end
end
end

auth_result(auth_options.info)
end

Expand Down