mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Allow default_url to be set for Devise::Failure app.
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
module Devise
|
||||
module Failure
|
||||
mattr_accessor :default_url
|
||||
|
||||
# Failure application that will be called every time :warden is thrown from
|
||||
# any strategy or hook. Responsible for redirect the user to the sign in
|
||||
# page based on current scope and mapping.
|
||||
# page based on current scope and mapping. If no scope is given, redirect
|
||||
# to the default_url.
|
||||
def self.call(env)
|
||||
options = env['warden.options']
|
||||
params = options[:params] || {}
|
||||
scope = options[:scope]
|
||||
mapping = Devise.mappings[scope]
|
||||
params = options[:params] || {}
|
||||
scope = options[:scope]
|
||||
|
||||
redirect_path = "/#{mapping.as}/#{mapping.path_names[:sign_in]}"
|
||||
redirect_path = if mapping = Devise.mappings[scope]
|
||||
"/#{mapping.as}/#{mapping.path_names[:sign_in]}"
|
||||
else
|
||||
"/#{default_url}"
|
||||
end
|
||||
|
||||
headers = {}
|
||||
headers["Location"] = redirect_path
|
||||
@@ -18,7 +23,6 @@ module Devise
|
||||
headers["Content-Type"] = 'text/plain'
|
||||
|
||||
message = options[:message] || "You are being redirected to #{redirect_path}"
|
||||
|
||||
[302, headers, message]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
# confirming it's account. If the user has not confirmed it's account during
|
||||
# this time frame, he/she will not able to sign in anymore.
|
||||
Warden::Manager.after_set_user do |record, auth, options|
|
||||
if record.present? && record.respond_to?(:active?) && !record.active?
|
||||
if record && record.respond_to?(:active?) && !record.active?
|
||||
scope = options[:scope]
|
||||
auth.logout(scope)
|
||||
throw :warden, :scope => scope, :params => {:unconfirmed => true}
|
||||
throw :warden, :scope => scope, :params => { :unconfirmed => true }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -43,8 +43,9 @@ module Devise
|
||||
# is already confirmed, add en error to email field
|
||||
def confirm!
|
||||
unless_confirmed do
|
||||
clear_confirmation_token
|
||||
update_attribute(:confirmed_at, Time.now)
|
||||
self.confirmation_token = nil
|
||||
self.confirmed_at = Time.now
|
||||
save(false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,15 +84,21 @@ module Devise
|
||||
# We do this by calculating if the difference between today and the
|
||||
# confirmation sent date does not exceed the confirm in time configured.
|
||||
# Confirm_in is a model configuration, must always be an integer value.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# # confirm_in = 1.day and confirmation_sent_at = today
|
||||
# confirmation_period_valid? # returns true
|
||||
#
|
||||
# # confirm_in = 5.days and confirmation_sent_at = 4.days.ago
|
||||
# confirmation_period_valid? # returns true
|
||||
#
|
||||
# # confirm_in = 5.days and confirmation_sent_at = 5.days.ago
|
||||
# confirmation_period_valid? # returns false
|
||||
#
|
||||
# # confirm_in = 0.days
|
||||
# confirmation_period_valid? # will always return false
|
||||
#
|
||||
def confirmation_period_valid?
|
||||
confirmation_sent_at? &&
|
||||
(Date.today - confirmation_sent_at.to_date).days < confirm_in
|
||||
@@ -128,11 +135,6 @@ module Devise
|
||||
generate_confirmation_token && save(false)
|
||||
end
|
||||
|
||||
# Removes confirmation token
|
||||
def clear_confirmation_token
|
||||
self.confirmation_token = nil
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
# Attempt to find a user by it's email. If a record is found, send new
|
||||
|
||||
@@ -12,7 +12,7 @@ module Devise
|
||||
success!(resource)
|
||||
else
|
||||
store_location
|
||||
throw :warden, :scope => scope, :params => {:unauthenticated => true}
|
||||
throw :warden, :scope => scope, :params => { :unauthenticated => true }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user