Sha256: 9a9db4131b9bb834618877de7c128a01489e237a4a7aa26950036e021d23626b
Contents?: true
Size: 968 Bytes
Versions: 7
Compression:
Stored size: 968 Bytes
Contents
module SimpleTokenAuthentication module ActsAsTokenAuthenticatable extend ActiveSupport::Concern # Please see https://gist.github.com/josevalim/fb706b1e933ef01e4fb6 # before editing this file, the discussion is very interesting. included do private :generate_authentication_token end def ensure_authentication_token if authentication_token.blank? self.authentication_token = generate_authentication_token end end def generate_authentication_token loop do token = Devise.friendly_token break token unless User.where(authentication_token: token).first end end module ClassMethods def acts_as_token_authenticatable(options = {}) include SimpleTokenAuthentication::ActsAsTokenAuthenticatable before_save :ensure_authentication_token end end end end ActiveRecord::Base.send :include, SimpleTokenAuthentication::ActsAsTokenAuthenticatable
Version data entries
7 entries across 7 versions & 1 rubygems