Sha256: fd57c940340f7698e483dc19f29f2ae7c56d3d078a998b3cfbba8f2c7b651a10
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
module Incline ## # Defines an auth engine. class AuthEngineBase ## # The auth engine initializer should take a hash of parameters. def initialize(options = {}) @options = options || {} end ## # The authenticate method takes an email and password to authenticate a user and the client IP for logging purposes. def authenticate(email, password, client_ip) nil end protected ## # Logs a failure message for a user. The user can either be an Incline::User model or the email address used # in the attempt. def add_failure_to(user, message, client_ip) # :doc: Incline::Log::info "LOGIN(#{user}) FAILURE FROM #{client_ip}: #{message}" history_length = 2 unless user.is_a?(::Incline::User) message = "[email: #{user}] #{message}" user = User.anonymous history_length = 6 end purge_old_history_for user, history_length user.login_histories.create(ip_address: client_ip, successful: false, message: message) end ## # Logs a success message for a user. def add_success_to(user, message, client_ip) # :doc: Incline::Log::info "LOGIN(#{user}) SUCCESS FROM #{client_ip}: #{message}" purge_old_history_for user user.login_histories.create(ip_address: client_ip, successful: true, message: message) end private def purge_old_history_for(user, max_months = 2) user.login_histories.where('incline_user_login_histories.created_at <= ?', Time.now - max_months.months).delete_all end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
incline-0.2.5 | lib/incline/auth_engine_base.rb |
incline-0.2.4 | lib/incline/auth_engine_base.rb |