| Module | Login::UsernameFinder |
| In: |
lib/login/username_finder.rb
|
An extremely simple module that allows me to put the logic for determining the username is one place.
Will get the currently configured username field. If not defined then email, then username, then user_name will be attempted. If none of those fields exist then nil is returned which will probably cause an error in the application.
# File lib/login/username_finder.rb, line 11
11: def username_field
12: # Let the app specified field take presedence
13: return User.username_field if User.respond_to? :username_field
14:
15: # Take a couple of guesses
16: %w(email username user_name).find do |fld|
17: User.column_names.include? fld
18: end
19: end