Module: Devise::Models::G5Authenticatable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise_g5_authenticatable/models/g5_authenticatable.rb,
lib/devise_g5_authenticatable/models/protected_attributes.rb
Overview
If this file is required, then protected attributes will be automatically mixed in to the g5 authenticatable model(s)
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #attributes_from_auth(auth_data) ⇒ Object
- #auth_user ⇒ Object
- #clean_up_passwords ⇒ Object
- #revoke_g5_credentials! ⇒ Object
- #update_from_auth(auth_data) ⇒ Object
- #update_g5_credentials(oauth_data) ⇒ Object
- #update_roles_from_auth(auth_data) ⇒ Object
- #update_with_password(params) ⇒ Object
- #valid_password?(password_to_check) ⇒ Boolean
Instance Method Details
#attributes_from_auth(auth_data) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 65 def attributes_from_auth(auth_data) { uid: auth_data.uid, provider: auth_data.provider, email: auth_data.info.email }.with_indifferent_access end |
#auth_user ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 26 def auth_user sync_auth_data rescue OAuth2::Error => e logger.error("Couldn't save user credentials because: #{e}") raise ActiveRecord::RecordNotSaved, e.code rescue StandardError => e logger.error("Couldn't save user credentials because: #{e}") raise ActiveRecord::RecordNotSaved, e. end |
#clean_up_passwords ⇒ Object
36 37 38 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 36 def clean_up_passwords self.password = self.password_confirmation = self.current_password = nil end |
#revoke_g5_credentials! ⇒ Object
60 61 62 63 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 60 def revoke_g5_credentials! self.g5_access_token = nil save! end |
#update_from_auth(auth_data) ⇒ Object
75 76 77 78 79 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 75 def update_from_auth(auth_data) assign_attributes(attributes_from_auth(auth_data)) update_g5_credentials(auth_data) update_roles_from_auth(auth_data) end |
#update_g5_credentials(oauth_data) ⇒ Object
56 57 58 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 56 def update_g5_credentials(oauth_data) self.g5_access_token = oauth_data.credentials.token end |
#update_roles_from_auth(auth_data) ⇒ Object
73 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 73 def update_roles_from_auth(auth_data); end |
#update_with_password(params) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 45 def update_with_password(params) updated_attributes = params.reject do |k, v| k =~ /password/ && v.blank? end current_password = updated_attributes.delete(:current_password) if valid_current_password?(current_password) update_attributes(updated_attributes) end end |
#valid_password?(password_to_check) ⇒ Boolean
40 41 42 43 |
# File 'lib/devise_g5_authenticatable/models/g5_authenticatable.rb', line 40 def valid_password?(password_to_check) validator = Devise::G5::AuthPasswordValidator.new(self) validator.valid_password?(password_to_check) end |