-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Juan Pablo Gil
committed
Oct 26, 2022
1 parent
3988a9e
commit 0e47fe7
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
#= User | ||
# | ||
# A person who has an account on the site (via Google Cloud Identity Platform). | ||
class User < ApplicationRecord | ||
validates :identity_platform_id, presence: true, uniqueness: true | ||
|
||
def self.from_identity_token(token) | ||
return unless token.valid? | ||
|
||
find_or_initialize_by(identity_platform_id: token.subject).tap do |user| | ||
user.update! token.payload.slice(:name, :email) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateUsers < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :users do |t| | ||
t.string :email | ||
t.string :name | ||
t.string :identity_platform_id, null: false | ||
|
||
t.timestamps | ||
|
||
t.index %i[identity_platform_id], name: :UK_user_identity_platform, unique: true | ||
end | ||
end | ||
end | ||
|