Sha256: e2628c91e5157d28aa39868fdd89c5dad103b464cbc4cc2c1c15a2918374da2d

Contents?: true

Size: 774 Bytes

Versions: 15

Compression:

Stored size: 774 Bytes

Contents

module Trestle
  module Auth
    module ModelMethods
      module Rememberable
        extend ActiveSupport::Concern

        def remember_me!
          update(remember_token: SecureRandom.urlsafe_base64(15), remember_token_expires_at: Time.now + Trestle.config.auth.remember.for)
        end

        def forget_me!
          update(remember_token: nil, remember_token_expires_at: nil)
        end

        def remember_token_expired?
          remember_token_expires_at.nil? || Time.now > remember_token_expires_at
        end

        module ClassMethods
          def authenticate_with_remember_token(token)
            user = find_by(remember_token: token)
            user if user && !user.remember_token_expired?
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
trestle-auth-0.5.0 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.5.0.pre2 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.5.0.pre lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.4.4 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.4.3 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.4.2 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.4.1 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.4.0 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.3.0 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.2.5 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.2.4 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.2.3 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.2.2 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.2.1 lib/trestle/auth/model_methods/rememberable.rb
trestle-auth-0.2.0 lib/trestle/auth/model_methods/rememberable.rb