lib/warden/strategies/base.rb in warden-1.2.3 vs lib/warden/strategies/base.rb in warden-1.2.4
- old
+ new
@@ -7,15 +7,15 @@
# The Warden::Strategies.add method is a simple way to provide custom strategies.
# You _must_ declare an @authenticate!@ method.
# You _may_ provide a @valid?@ method.
# The valid method should return true or false depending on if the strategy is a valid one for the request.
#
- # The parameters for Warden::Strategies.add method is:
+ # The parameters for Warden::Strategies.add method are:
# <label: Symbol> The label is the name given to a strategy. Use the label to refer to the strategy when authenticating
- # <strategy: Class|nil> The optional stragtegy argument if set _must_ be a class that inherits from Warden::Strategies::Base and _must_
+ # <strategy: Class|nil> The optional strategy argument if set _must_ be a class that inherits from Warden::Strategies::Base and _must_
# implement an @authenticate!@ method
- # <block> The block acts as a convinient way to declare your strategy. Inside is the class definition of a strategy.
+ # <block> The block acts as a convenient way to declare your strategy. Inside is the class definition of a strategy.
#
# Examples:
#
# Block Declared Strategy:
# Warden::Strategies.add(:foo) do
@@ -106,12 +106,17 @@
# A simple method to return from authenticate! if you want to ignore this strategy
# :api: public
def pass; end
+ # Returns true only if the result is a success and a user was assigned.
+ def successful?
+ @result == :success && !user.nil?
+ end
+
# Whenever you want to provide a user object as "authenticated" use the +success!+ method.
- # This will halt the strategy, and set the user in the approprieate scope.
+ # This will halt the strategy, and set the user in the appropriate scope.
# It is the "login" method
#
# Parameters:
# user - The user object to login. This object can be anything you have setup to serialize in and out of the session
#
@@ -131,22 +136,22 @@
halt!
@message = message
@result = :failure
end
- # Casuses the strategy to fail, but not halt. The strategies will cascade after this failure and warden will check the next strategy. The last strategy to fail will have it's message displayed.
+ # Causes the strategy to fail, but not halt. The strategies will cascade after this failure and warden will check the next strategy. The last strategy to fail will have it's message displayed.
# :api: public
def fail(message = "Failed to Login")
@message = message
@result = :failure
end
# Causes the authentication to redirect. An :warden symbol must be thrown to actually execute this redirect
#
# Parameters:
# url <String> - The string representing the URL to be redirected to
- # pararms <Hash> - Any parameters to encode into the URL
- # opts <Hash> - Any options to recirect with.
+ # params <Hash> - Any parameters to encode into the URL
+ # opts <Hash> - Any options to redirect with.
# available options: permanent => (true || false)
#
# :api: public
def redirect!(url, params = {}, opts = {})
halt!