1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
module OpenIDConnect
class ResponseObject
class UserInfo < ConnectObject
attr_optional(
:sub,
:name,
:given_name,
:family_name,
:middle_name,
:nickname,
:preferred_username,
:profile,
:picture,
:website,
:email,
:email_verified,
:gender,
:birthdate,
:zoneinfo,
:locale,
:phone_number,
:phone_number_verified,
:address,
:updated_at
)
alias_method :subject, :sub
alias_method :subject=, :sub=
validates :email_verified, :phone_number_verified, allow_nil: true, inclusion: {in: [true, false]}
validates :zoneinfo, allow_nil: true, inclusion: {in: TZInfo::TimezoneProxy.all.collect(&:name)}
validates :profile, :picture, :website, allow_nil: true, url: true
validates :email, allow_nil: true, email: true
validates :updated_at, allow_nil: true, numericality: {only_integer: true}
validate :validate_address
validate :require_at_least_one_attributes
# TODO: validate locale
def initialize(attributes = {})
super
(all_attributes - [:email_verified, :phone_number_verified, :address, :updated_at]).each do |key|
self.send "#{key}=", self.send(key).try(:to_s)
end
self.updated_at = updated_at.try(:to_i)
end
def validate_address
errors.add :address, address.errors.full_messages.join(', ') if address.present? && !address.valid?
end
undef :address=
def address=(hash_or_address)
@address = case hash_or_address
when Hash
Address.new hash_or_address
when Address
hash_or_address
end
end
end
end
end
Dir[File.dirname(__FILE__) + '/user_info/*.rb'].each do |file|
require file
end
|