Skip to content

Commit 8870812

Browse files
author
Juan Pablo Gil
committed
Add user modelo simulation
1 parent 8f6d400 commit 8870812

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
#= User
4+
#
5+
# A person who has an account on the site (via Google Cloud Identity Platform).
6+
class User < ApplicationRecord
7+
validates :identity_platform_id, presence: true, uniqueness: true
8+
9+
def self.from_identity_token(token)
10+
return unless token.valid?
11+
12+
find_or_initialize_by(identity_platform_id: token.subject).tap do |user|
13+
user.update! token.payload.slice(:name, :email)
14+
end
15+
end
16+
end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
class CreateUsers < ActiveRecord::Migration[7.0]
4+
def change
5+
create_table :users do |t|
6+
t.string :email
7+
t.string :name
8+
t.string :identity_platform_id, null: false
9+
10+
t.timestamps
11+
12+
t.index %i[identity_platform_id], name: :UK_user_identity_platform, unique: true
13+
end
14+
end
15+
end
16+

0 commit comments

Comments
 (0)