mirror of
https://github.com/go-gitnub/gitnub.git
synced 2024-11-15 02:32:51 +00:00
56 lines
1.9 KiB
Ruby
56 lines
1.9 KiB
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
# == Schema Information
|
||
|
#
|
||
|
# Table name: users
|
||
|
#
|
||
|
# id :bigint not null, primary key
|
||
|
# confirmation_sent_at :datetime
|
||
|
# confirmation_token :string
|
||
|
# confirmed_at :datetime
|
||
|
# current_sign_in_at :datetime
|
||
|
# current_sign_in_ip :string
|
||
|
# email :string default(""), not null
|
||
|
# encrypted_password :string default(""), not null
|
||
|
# last_sign_in_at :datetime
|
||
|
# last_sign_in_ip :string
|
||
|
# remember_created_at :datetime
|
||
|
# reset_password_sent_at :datetime
|
||
|
# reset_password_token :string
|
||
|
# sign_in_count :integer default(0), not null
|
||
|
# unconfirmed_email :string
|
||
|
# username :string default(""), not null
|
||
|
# created_at :datetime not null
|
||
|
# updated_at :datetime not null
|
||
|
#
|
||
|
# Indexes
|
||
|
#
|
||
|
# index_users_on_confirmation_token (confirmation_token) UNIQUE
|
||
|
# index_users_on_email (email) UNIQUE
|
||
|
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
||
|
# index_users_on_username (username) UNIQUE
|
||
|
#
|
||
|
class User < ApplicationRecord
|
||
|
# Include default devise modules. Others available are:
|
||
|
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
||
|
devise :database_authenticatable, :registerable,
|
||
|
:recoverable, :rememberable, :validatable,
|
||
|
:confirmable, :trackable
|
||
|
|
||
|
attr_writer :login
|
||
|
|
||
|
def login
|
||
|
@login || username || email
|
||
|
end
|
||
|
|
||
|
def self.find_for_database_authentication(warden_conditions)
|
||
|
conditions = warden_conditions.dup
|
||
|
if login == conditions.delete(:login)
|
||
|
where(conditions.to_h).where(['lower(username) = :value OR lower(email) = :value',
|
||
|
{ value: login.downcase }]).first
|
||
|
elsif conditions.key?(:username) || conditions.key?(:email)
|
||
|
where(conditions.to_h).first
|
||
|
end
|
||
|
end
|
||
|
end
|