mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
closes #1658 added test for openid fixed robocup offences written tests for email presence validation minor changes shifted omniauth callback tests to rspec controllers fixed linting bug minor changes minor changes
20 lines
599 B
Ruby
20 lines
599 B
Ruby
class Openid < ApplicationRecord
|
|
belongs_to :user
|
|
validates :provider, :uid, :email, presence: true
|
|
|
|
# Searches for openid based on provider and uid.
|
|
# Returns found openid or a new openid.
|
|
# ====Returns
|
|
# * Openid::ActiveRecord_Relation -> openid
|
|
def self.find_for_oauth(auth)
|
|
openid = Openid.where(provider: auth.provider, uid: auth.uid).first_or_initialize
|
|
|
|
if openid.new_record?
|
|
openid.email = auth.info.email
|
|
if (existing_openid = Openid.where(email: openid.email).first)
|
|
openid.user_id = existing_openid.user_id
|
|
end
|
|
end
|
|
openid
|
|
end
|
|
end
|