Permalink
Browse files

Tidy up lose ends.

  • Loading branch information...
1 parent 8bf6a66 commit 0aa41d638871f4022c2c1583d0b68980f730eddd @josevalim josevalim committed Jul 13, 2010
@@ -3,7 +3,7 @@ class Devise::ConfirmationsController < ApplicationController
# GET /resource/confirmation/new
def new
- build_resource
+ build_resource({})
render_with_scope :new
end
@@ -4,7 +4,7 @@ class Devise::PasswordsController < ApplicationController
# GET /resource/password/new
def new
- build_resource
+ build_resource({})
render_with_scope :new
end
@@ -4,7 +4,7 @@ class Devise::UnlocksController < ApplicationController
# GET /resource/unlock/new
def new
- build_resource
+ build_resource({})
render_with_scope :new
end
@@ -70,7 +70,7 @@ def resource=(new_resource)
# Build a devise resource.
def build_resource(hash=nil)
hash ||= params[resource_name] || {}
- self.resource = resource_class.new(hash)
+ self.resource = resource_class.new_with_session(hash, session)
end
# Helper for use in before_filters where no authentication is required.
@@ -95,9 +95,11 @@ def require_no_authentication
#
# Please refer to README or en.yml locale file to check what messages are
# available.
- def set_flash_message(key, kind) #:nodoc:
- flash[key] = I18n.t(:"#{resource_name}.#{kind}", :resource_name => resource_name,
- :scope => [:devise, controller_name.to_sym], :default => kind)
+ def set_flash_message(key, kind, options={}) #:nodoc:
+ options[:scope] = "devise.#{controller_name}"
+ options[:default] = Array(options[:default]).unshift(kind)
+ options[:resource_name] = resource_name
+ flash[key] = I18n.t(:"#{resource_name}.#{kind}", options)
end
def clean_up_passwords(object) #:nodoc:
@@ -79,6 +79,12 @@ def http_authenticatable?(strategy)
http_authenticatable.include?(strategy) : http_authenticatable
end
+ # By default discards all information sent by the session by calling
+ # new with params.
+ def new_with_session(params, session)
+ new(params)
+ end
+
# Find first record based on conditions given (ie by the sign in form).
# Overwrite to add customized conditions, create a join, or maybe use a
# namedscope to filter records while authenticating.
@@ -50,14 +50,18 @@ def callback_action
self.resource = resource_class.send(oauth_model_callback, access_token, signed_in_resource)
if resource.persisted?
- # ADD FLASH MESSAGE
+ set_flash_message :notice, oauth_callback, :default => :default, :kind => oauth_callback.to_s.titleize
sign_in_and_redirect resource_name, resource, :event => :authentication
else
- # STORE STUFF IN SESSION
+ session[oauth_session_scope] = access_token.token
render_for_oauth
end
end
+ def oauth_session_scope
+ "#{resource_name}_#{oauth_callback}_token"
+ end
+
# Overwrite redirect_for_sign_in so it takes uses after_oauth_sign_in_path_for.
def redirect_for_sign_in(scope, resource) #:nodoc:
redirect_to stored_location_for(scope) || after_oauth_sign_in_path_for(resource)

0 comments on commit 0aa41d6

Please sign in to comment.