mirror of
https://github.com/we-promise/sure.git
synced 2026-04-08 06:44:52 +00:00
* Eliminate duplication by using create_from_omniauth method - Updated OidcIdentity.create_from_omniauth to set last_authenticated_at - Refactored OidcAccountsController to use create_from_omniauth instead of direct create! calls - Updated test to verify last_authenticated_at is set by create_from_omniauth Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * Extract auth hash building into private helper method - Added build_auth_hash helper method to eliminate OpenStruct creation duplication - Both create_link and create_user actions now use the same helper Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * Linter fix * Fix button style on OIDC link step * Fix dark mode styles --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
29 lines
746 B
Ruby
29 lines
746 B
Ruby
class OidcIdentity < ApplicationRecord
|
|
belongs_to :user
|
|
|
|
validates :provider, presence: true
|
|
validates :uid, presence: true, uniqueness: { scope: :provider }
|
|
validates :user_id, presence: true
|
|
|
|
# Update the last authenticated timestamp
|
|
def record_authentication!
|
|
update!(last_authenticated_at: Time.current)
|
|
end
|
|
|
|
# Extract and store relevant info from OmniAuth auth hash
|
|
def self.create_from_omniauth(auth, user)
|
|
create!(
|
|
user: user,
|
|
provider: auth.provider,
|
|
uid: auth.uid,
|
|
info: {
|
|
email: auth.info&.email,
|
|
name: auth.info&.name,
|
|
first_name: auth.info&.first_name,
|
|
last_name: auth.info&.last_name
|
|
},
|
|
last_authenticated_at: Time.current
|
|
)
|
|
end
|
|
end
|