Sha256: 80f6d18f1214ad0d1f15fc5d1f564d9611fa569feace5effd16c6d96270aff42
Contents?: true
Size: 1.5 KB
Versions: 3
Compression:
Stored size: 1.5 KB
Contents
module Devise class PinfirmableController < DeviseController def new @locked_out = locked_out? end def create if locked_out? @locked_out = true render(:new, status: 429) && return end if Pinfirmable::Pin.new(params[:digits]).matches_user_pin(pinfirmable_user) pinfirmable_user.confirm redirect_to after_confirmation_path_for(resource_name, pinfirmable_user) else tries = pinfirmable_user.pinfirmable_tries += 1 lockout = (tries % 3).zero? ? (tries / 3).minute.from_now : nil pinfirmable_user.update_attributes( pinfirmable_tries: tries, pinfirmable_lockout: lockout ) redirect_to user_confirmemail_path end end def resend_email flash[:notice] = "We have just resent your code" PinfirmableMailer.pin_email(pinfirmable_user).deliver redirect_to user_confirmemail_path end protected def pinfirmable_user request.env["CHECKING_PINFIRMABLE_PIN"] = true pu = current_user request.env["CHECKING_PINFIRMABLE_PIN"] = false pu end def locked_out? return false unless pinfirmable_user return false if pinfirmable_user.pinfirmable_lockout.nil? pinfirmable_user.pinfirmable_lockout > Time.now end def after_confirmation_path_for(resource_name, resource) if signed_in?(resource_name) signed_in_root_path(resource) else new_session_path(resource_name) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems