Class: Pwb::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Pwb::User
- Defined in:
- app/models/pwb/user.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_authorization(auth) ⇒ Object
-
#default_client_locale ⇒ Object
TODO: - use db col for below.
Class Method Details
.find_for_oauth(auth) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/pwb/user.rb', line 16 def self.find_for_oauth(auth) = Authorization.where(provider: auth.provider, uid: auth.uid.to_s).first return .user if email = auth.info[:email] unless email.present? # below is a workaround for when email is not available from auth provider email = "#{SecureRandom.urlsafe_base64}@example.com" # in future might redirect to a page where email can be requested end user = User.where(email: email).first if user user.(auth) else # need to prefix Devise with :: to avoid confusion with Pwb::Devise password = ::Devise.friendly_token[0, 20] user = User.create!(email: email, password: password, password_confirmation: password) user.(auth) end user end |
Instance Method Details
#create_authorization(auth) ⇒ Object
39 40 41 |
# File 'app/models/pwb/user.rb', line 39 def (auth) .create(provider: auth.provider, uid: auth.uid) end |
#default_client_locale ⇒ Object
TODO: - use db col for below
12 13 14 |
# File 'app/models/pwb/user.rb', line 12 def default_client_locale :en end |