active_directory_login 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47fbbe0fe7ddb8fd3ec3ba897b83d98ba377e915
4
- data.tar.gz: bfa62e77801d567ca7d95fff669f792c8f84b443
3
+ metadata.gz: 35dbce9c799a3b240d53d37db932486d6b13b138
4
+ data.tar.gz: 897280b514e3103f8be0fbf6ea37f2482064458a
5
5
  SHA512:
6
- metadata.gz: 613463170d1b6f58ce61c69171f277901a0f6c5e93641db2a98ecc6c22ac3c26123ad5f5bf03dab4ae28a689c29eddd84ff11d7a0290dd336df220ff1d3353ad
7
- data.tar.gz: 70010927678048f1713484efade2d723f113bab7d2766e5cbabc34f09c543a27ebc191e9ab2a9b1cbf2bbb6aa77cfb64d9b224f7a2641684a0b007ede983cefb
6
+ metadata.gz: a59a6f2317c42c66fbf0773a435a64ec474c3bca2a7ff64bb0d6c4ef9e9f03e72a576e565cd879d25bb995b642ac75a0c8ff07ad51f41507d3545719becf9187
7
+ data.tar.gz: e628d1e43fe5e7d8ea607a66cf43de44810377cacc1d35fd333cd5dd4bee9bfd49c19dfad41e3dc2297c5adb4a0241e7cebaad42958355cfb1171517e58dd550
@@ -62,10 +62,9 @@ module ActiveDirectoryLogin
62
62
 
63
63
  def with_user(username_or_email, password, &block)
64
64
  raise Error, "block required" if block.nil?
65
-
66
65
  @ad_user = find_user(username_or_email)
67
66
  @ad_user_password = password
68
- @query = query(username_or_email)
67
+ @query = query
69
68
  @app_user = @query.first
70
69
 
71
70
  value = block.call
@@ -93,10 +92,9 @@ module ActiveDirectoryLogin
93
92
  @ad_user.try(:authenticate, @ad_user_password)
94
93
  end
95
94
 
96
- def query(username_or_email)
97
- @query ||= (username_or_email =~ /@/) ?
98
- User.where { (provider == User::LDAP) & (email =~ username_or_email) } :
99
- User.where { (provider == User::LDAP) & (username =~ username_or_email) }
95
+ def query
96
+ ad_email = @ad_user.mail.downcase
97
+ @query = User.where { (provider == User::LDAP) & (email =~ ad_email) }
100
98
  end
101
99
 
102
100
  def create_or_update_user
@@ -105,7 +103,7 @@ module ActiveDirectoryLogin
105
103
  name: "#{@ad_user.givenname} #{@ad_user.sn}",
106
104
  email: @ad_user.mail.downcase,
107
105
  username: @ad_user[:sAMAccountName]
108
- )
106
+ )
109
107
 
110
108
  # Update the user's password and permissions (can't use update_attributes as it might not be saved yet)
111
109
  user.password = @ad_user_password
@@ -127,6 +125,10 @@ module ActiveDirectoryLogin
127
125
 
128
126
  ad_key = (username_or_email =~ /@/) ? :mail : :sAMAccountName
129
127
  ad_user = ActiveDirectory::User.find(:first, ad_key => username_or_email)
128
+ if ad_user.nil? # User hasnt used their primary email so try the secondary
129
+ ad_user = ActiveDirectory::User.find(:first, "msrtcsip-primaryuseraddress" => "sip:#{username_or_email}")
130
+ end
131
+ ad_user
130
132
  end
131
133
 
132
134
 
@@ -183,7 +185,7 @@ module ActiveDirectoryLogin
183
185
  staff_unchanged_emails = staff_unchanged.collect(&:email)
184
186
 
185
187
  # create any new staff
186
- pending = Array(staff_member_emails - staff_allowed_emails - staff_disallowed_emails - staff_unchanged_emails)
188
+ pending = Array(staff_member_emails - staff_allowed_emails - staff_unchanged_emails)
187
189
  pending.each do |pending_email|
188
190
  with_user(pending_email, SecureRandom.hex){ create_or_update_user }
189
191
  end
@@ -207,8 +209,8 @@ module ActiveDirectoryLogin
207
209
  superuser_unchanged_emails = superuser_unchanged.collect(&:email)
208
210
 
209
211
  # create any new superuser
210
- pending = Array(superuser_member_emails - superuser_allowed_emails - superuser_disallowed_emails - superuser_unchanged_emails)
211
- pending.each do |pending_email|
212
+ pending = Array(superuser_member_emails - superuser_allowed_emails - superuser_unchanged_emails)
213
+ pending.each do |pending_email|
212
214
  with_user(pending_email, SecureRandom.hex){ create_or_update_user }
213
215
  end
214
216
  superuser_created_emails = pending
@@ -218,7 +220,6 @@ module ActiveDirectoryLogin
218
220
 
219
221
  ## update users
220
222
  user_group = find_group(user_dn)
221
-
222
223
  member_emails = user_group.member.collect(&:mail).map(&:downcase)
223
224
  member_emails = member_emails - superuser_member_emails - staff_member_emails
224
225
 
@@ -234,7 +235,7 @@ module ActiveDirectoryLogin
234
235
  user_unchanged_emails = user_unchanged.collect(&:email)
235
236
 
236
237
  #create any new user
237
- pending = Array(pending - user_allowed_emails - user_unchanged_emails)
238
+ pending = Array(member_emails - user_allowed_emails - user_unchanged_emails)
238
239
  pending.each do |pending_email|
239
240
  with_user(pending_email, SecureRandom.hex){ create_or_update_user }
240
241
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveDirectoryLogin
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_directory_login
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Murray
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler