Class: Cms::ExternalUser
- Inherits:
-
PersistentUser
- Object
- ActiveRecord::Base
- PersistentUser
- Cms::ExternalUser
- Defined in:
- app/models/cms/external_user.rb
Overview
Represents a user that has been authenticated from an external data source. Typical use case might be:
“‘
# Assumes there is an external Crm tool that we look up username/passwords from.
if(SouthparkCrm::Client.authenticate(params[:login], params[:password]))
user = Cms::ExternalUser.authenticate('stan.marsh', 'southpark-crm')
user.(Cms::UsersService::GROUP_CMS_ADMIN)
end “‘
Class Method Summary collapse
-
.authenticate(login, source, info = {}) ⇒ Cms::ExternalUser
Returns an authenticated external user.
-
.work_around_rails_4_serialization_bug(info) ⇒ Object
Rails 4.0.2 bug: If some value (even {}) for external_data is not specified, then a serialization error occurs.
Instance Method Summary collapse
-
#authorize(*group_codes) ⇒ Object
Authorize this particular user to be part of one or more groups.
-
#password_changeable? ⇒ Boolean
Determines if this User can have their password changed.
Methods inherited from PersistentUser
able_to_edit_or_publish_content, #active_for_authentication?, #cas_extra_attributes=, current, current=, #disable, #disable!, #enable, #enable!, #expired?, #expires_at_formatted, #full_name, #group_codes, #group_codes=, guest, #guest?, permitted_params
Methods included from DefaultAccessible
#non_permitted_params, #permitted_params
Class Method Details
.authenticate(login, source, info = {}) ⇒ Cms::ExternalUser
Returns an authenticated external user. If this is the first time this account has been logged in, this will create a new User row as a side effect. Otherwise, it returns the existing user account.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/cms/external_user.rb', line 27 def authenticate(login, source, info={}) info = work_around_rails_4_serialization_bug(info) criteria = {login: login, source: source} existing = Cms::ExternalUser.where(criteria).first if existing existing.update(info) return existing end criteria.merge!(info) new_user = Cms::ExternalUser.create!(criteria) new_user.groups << Cms::Group.guest if Cms::Group.guest new_user end |
.work_around_rails_4_serialization_bug(info) ⇒ Object
Rails 4.0.2 bug: If some value (even {}) for external_data is not specified, then a serialization error occurs.
42 43 44 |
# File 'app/models/cms/external_user.rb', line 42 def work_around_rails_4_serialization_bug(info) {external_data: {}}.merge(info) end |
Instance Method Details
#authorize(*group_codes) ⇒ Object
Authorize this particular user to be part of one or more groups. This will overwrite any previous group membership. Typically this would be called after authenticating a user.
55 56 57 58 |
# File 'app/models/cms/external_user.rb', line 55 def (*group_codes) new_groups = group_codes.collect { |code| Cms::Group.with_code(code).first } self.groups = new_groups end |
#password_changeable? ⇒ Boolean
Determines if this User can have their password changed.
48 49 50 |
# File 'app/models/cms/external_user.rb', line 48 def password_changeable? false end |