Module: Jm81auth::Models::User::ClassMethods
- Defined in:
- lib/jm81auth/models/user.rb
Instance Method Summary collapse
-
#find_by_email(email) ⇒ User?
Find user by email address.
-
#oauth_login(oauth) ⇒ AuthToken
Login from OAuth.
Instance Method Details
#find_by_email(email) ⇒ User?
Find user by email address. Returns nil if the email address is not valid (for a minimal version of valid)
26 27 28 29 30 31 32 |
# File 'lib/jm81auth/models/user.rb', line 26 def find_by_email email if email.to_s =~ EMAIL_REGEX where(email: email.to_s.downcase.strip).first else nil end end |
#oauth_login(oauth) ⇒ AuthToken
Login from OAuth.
First try to find an AuthMethod matching the provider data. If none, find or create a User based on email, then create an AuthMethod. Finally, create and return an AuthToken.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/jm81auth/models/user.rb', line 44 def oauth_login oauth method = ::AuthMethod.by_provider_data oauth.provider_data if !method user = find_by_email(oauth.email) || create( email: oauth.email.downcase, display_name: oauth.display_name ) method = user.add_auth_method oauth.provider_data end method.create_token end |