Commit 3bf68af3 authored by zauberstuhl's avatar zauberstuhl

Use maildrop as default mail address

parent c4f78223
......@@ -2,11 +2,13 @@ class LDAPUser
attr_reader :name, :email, :username, :user
def initialize (auth_info)
@name = auth_info[:name]
@email = auth_info[:email]
@username = auth_info[:nickname]
@name = auth_info.cn[0]
@email = auth_info.maildrop[0]
@email ||= auth_info.mail[0]
@username = auth_info.uid[0]
@user = SiteSetting.ldap_lookup_users_by == 'username' ? User.find_by_username(@username) : User.find_by_email(@email)
create_user_groups(auth_info[:groups]) unless self.account_exists?
#create_user_groups(auth_info.groups) unless self.account_exists?
create_user unless self.account_exists?
end
def auth_result
......@@ -25,14 +27,15 @@ class LDAPUser
end
private
def create_user_groups(user_groups)
return if user_groups.nil?
#def create_user_groups(user_groups)
def create_user
#return if user_groups.nil?
#user account must exist in order to create user groups
@user = User.create!(name: self.name, email: self.email, username: self.username)
@user.activate
user_groups.each do |group_name|
group = Group.find_by(name: group_name)
@user.groups << group unless group.nil?
end
#user_groups.each do |group_name|
# group = Group.find_by(name: group_name)
# @user.groups << group unless group.nil?
#end
end
end
......@@ -23,7 +23,7 @@ class LDAPAuthenticator < ::Auth::Authenticator
end
def after_authenticate(auth_options)
return auth_result(auth_options.info)
return auth_result(auth_options.extra.raw_info)
end
def register_middleware(omniauth)
......@@ -54,10 +54,10 @@ class LDAPAuthenticator < ::Auth::Authenticator
user_descriptions = load_user_descriptions
return fail_auth('List of users must be provided when ldap_user_create_mode setting is set to \'list\'.') if user_descriptions.nil?
#match on email
match = user_descriptions.find { |ud| auth_info[:email].casecmp(ud[:email]) == 0 }
match = user_descriptions.find { |ud| auth_info.mail[0].casecmp(ud[:email]) == 0 }
return fail_auth('User with email is not listed in LDAP user list.') if match.nil?
match[:nickname] = match[:username] || auth_info[:nickname]
match[:name] = match[:name] || auth_info[:name]
match[:nickname] = match[:username] || auth_info.uid[0]
match[:name] = match[:name] || auth_info.cn[0]
return LDAPUser.new(match).auth_result
when 'auto'
return LDAPUser.new(auth_info).auth_result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment