40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: users
|
|
#
|
|
# id :bigint not null, primary key
|
|
# avatar_url :string
|
|
# email :string default(""), not null
|
|
# encrypted_password :string default(""), not null
|
|
# name :string not null
|
|
# remember_created_at :datetime
|
|
# reset_password_sent_at :datetime
|
|
# reset_password_token :string
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_users_on_email (email) UNIQUE
|
|
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
|
#
|
|
class User < ApplicationRecord
|
|
devise :database_authenticatable,
|
|
:registerable,
|
|
:recoverable,
|
|
:rememberable,
|
|
:validatable,
|
|
:omniauthable,
|
|
omniauth_providers: [:google_oauth2]
|
|
|
|
has_and_belongs_to_many :roles
|
|
|
|
validates :name, presence: true
|
|
|
|
def self.from_omniauth(email, avatar_url)
|
|
@user = User.find_by!(email: email)
|
|
@user.update(avatar_url: avatar_url)
|
|
@user
|
|
end
|
|
end
|