Sha256: e38d16cfd8085b04db9225ec32797c89889debef85d675c17e0879bea5ef6709

Contents?: true

Size: 650 Bytes

Versions: 2

Compression:

Stored size: 650 Bytes

Contents

module UserAuthentication
	extend ActiveSupport::Concern

	included do

		include JT::Rails::Tokenizable

		has_secure_password

		tokenize :password_token

		validates :email, presence: true, email_format: true, uniqueness: { case_sensitive: false}
		
		before_save :downcase_email

		scope :search_by_email_for_authentication, ->(email = nil) { where(email: email.to_s.downcase).where('password_digest IS NOT NULL') }

	end

	module ClassMethods

		def authenticate(email, password)
			self.search_by_email_for_authentication(email).first.try(:authenticate, password)
		end

	end

	def downcase_email
		self.email.downcase! if self.email
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jt-rails-generator-user-1.0.4 lib/generators/jt/user/templates/models/concerns/user_authentication.rb
jt-rails-generator-user-1.0.3 lib/generators/jt/user/templates/models/concerns/user_authentication.rb