user.rb 777 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class User < ApplicationRecord
  3. devise :database_authenticatable, :lockable, :recoverable, :rememberable,
  4. :trackable, :validatable, :confirmable, :registerable
  5. devise :omniauthable, omniauth_providers: %i[reddit google_oauth2 discord]
  6. # Note: devise :validatable above adds validations for :email and :password
  7. # validates :username, presence: true, length: {maximum: 128}
  8. validates :email, confirmation: true
  9. def self.from_omniauth(auth)
  10. where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
  11. user.email = auth.info.email
  12. user.password = Devise.friendly_token[0, 20]
  13. # Reddit, Google, and Discord both have email verification already
  14. user.skip_confirmation!
  15. end
  16. end
  17. end