Sha256: 5cf3cbe47ac1c2a90b6154d0c4a89887bffad58556616e17501f67f70c561963
Contents?: true
Size: 1.44 KB
Versions: 3
Compression:
Stored size: 1.44 KB
Contents
module OpenStax module Accounts class SessionsCallback lev_handler protected def setup @auth_data = request.env['omniauth.auth'] end def authorized? @auth_data.provider == 'openstax' end def handle # Don't worry if the account is logged in or not beforehand. Just assume that they aren't. # tap is used because we want the block to always run (not just when initializing) begin outputs.account = Account.find_or_initialize_by( openstax_uid: @auth_data.uid ).tap do |account| account.access_token = @auth_data.credentials.token raw_info = @auth_data.extra.raw_info OpenStax::Accounts::Account::SYNC_ATTRIBUTES.each do |attribute| begin account.send "#{attribute}=", raw_info[attribute] rescue ArgumentError # Ignore errors, for example if enum values are invalid end end # Gracefully handle absent and unknown enum values account.faculty_status ||= :no_faculty_info account.role ||= :unknown_role account.school_type ||= :unknown_school_type end outputs.account.save if outputs.account.changed? rescue ActiveRecord::RecordNotUnique retry end transfer_errors_from(outputs.account, type: :verbatim) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems