Commit 141fa98c4ec2d9373513bfb9f17ee2a3d0113a2f
1 parent
ee712409
Exists in
master
and in
22 other branches
Fix ldap plugin hotspot behaviour
Showing
1 changed file
with
20 additions
and
6 deletions
Show diff stats
plugins/ldap/lib/ldap_plugin.rb
| ... | ... | @@ -18,7 +18,8 @@ class LdapPlugin < Noosfero::Plugin |
| 18 | 18 | # - login received by ldap |
| 19 | 19 | # - params from current context |
| 20 | 20 | # returns = updated person_data hash |
| 21 | - def ldap_plugin_set_profile_data(attrs, login, params) | |
| 21 | + def ldap_plugin_set_profile_data(attrs, params) | |
| 22 | + [attrs, params] | |
| 22 | 23 | end |
| 23 | 24 | |
| 24 | 25 | # -> Custom ldap plugin hotspot to update user object |
| ... | ... | @@ -55,19 +56,22 @@ class LdapPlugin < Noosfero::Plugin |
| 55 | 56 | |
| 56 | 57 | if attrs |
| 57 | 58 | user.login = login |
| 58 | - user.email = attrs[:mail] | |
| 59 | + user.email = get_email(attrs, login) | |
| 59 | 60 | user.name = attrs[:fullname] |
| 60 | 61 | user.password = password |
| 61 | 62 | user.password_confirmation = password |
| 62 | - person_data = plugins.dispatch(:ldap_plugin_set_profile_data, attrs, login, context.params) | |
| 63 | - user.person_data = person_data.blank? ? context.params[:profile_data] : person_data | |
| 63 | + user.person_data = plugins.pipeline(:ldap_plugin_set_profile_data, attrs, context.params).last[:profile_data] | |
| 64 | 64 | user.activated_at = Time.now.utc |
| 65 | 65 | user.activation_code = nil |
| 66 | 66 | |
| 67 | 67 | ldap = LdapAuthentication.new(context.environment.ldap_plugin_attributes) |
| 68 | 68 | begin |
| 69 | - user = nil unless user.save! | |
| 70 | - plugins.dispatch(:ldap_plugin_update_user, user, attrs) | |
| 69 | + if user.save | |
| 70 | + user.activate | |
| 71 | + plugins.dispatch(:ldap_plugin_update_user, user, attrs) | |
| 72 | + else | |
| 73 | + user = nil | |
| 74 | + end | |
| 71 | 75 | rescue |
| 72 | 76 | #User not saved |
| 73 | 77 | end |
| ... | ... | @@ -90,6 +94,16 @@ class LdapPlugin < Noosfero::Plugin |
| 90 | 94 | user |
| 91 | 95 | end |
| 92 | 96 | |
| 97 | + def get_email(attrs, login) | |
| 98 | + return attrs[:mail] unless attrs[:mail].blank? | |
| 99 | + | |
| 100 | + if attrs[:fullname] | |
| 101 | + return attrs[:fullname].to_slug + "@ldap.user" | |
| 102 | + else | |
| 103 | + return login.to_slug + "@ldap.user" | |
| 104 | + end | |
| 105 | + end | |
| 106 | + | |
| 93 | 107 | def login_extra_contents |
| 94 | 108 | proc do |
| 95 | 109 | @person = Person.new(:environment => @environment) | ... | ... |