initial rebuild from v1
This commit is contained in:
36
app/models/user.rb
Normal file
36
app/models/user.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Model: User
|
||||
#
|
||||
# Description: Define an application user. the only authentication mecanism
|
||||
# is omniauthable with the BattleNet API
|
||||
class User < ApplicationRecord
|
||||
devise :rememberable, :omniauthable, omniauth_providers: [:bnet]
|
||||
|
||||
has_many :wow_characters, dependent: :destroy
|
||||
|
||||
validates :battletag, presence: true, uniqueness: true
|
||||
|
||||
def self.from_omniauth(auth)
|
||||
user = User.where(provider: auth.provider, uid: auth.uid).first_or_initialize
|
||||
|
||||
user.provider = auth.provider
|
||||
user.uid = auth.uid
|
||||
user.battletag = auth.info.battletag
|
||||
user.token_expires = auth.credentials.expires
|
||||
user.token_expire_at = Time.at(auth.credentials.expires_at).utc
|
||||
user.token = auth.credentials.token
|
||||
|
||||
user.save
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
def self.new_with_session(params, session)
|
||||
super.tap do |user|
|
||||
if (data = session['devise.bnet_data']) && session['devise.bnet_data']['extra']['raw_info']
|
||||
user.email = data['email'] if user.email.blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user