1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Changing resource_home_path to resource_root_path and add the same redirect to confirmation and password.

This commit is contained in:
Carlos A. da Silva 2009-10-19 00:38:50 -02:00
parent cce3f58e83
commit fc08a7c5ac
6 changed files with 20 additions and 7 deletions

View file

@ -134,6 +134,8 @@ You have also access to the session for this scope:
user_session user_session
After signing in a user, confirming it's account or updating it's password, devise will look for a scoped root path to redirect. Example: For a :user resource, it will use user_root_path if it exists, otherwise default root_path will be used.
Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps: Devise let's you setup as many roles as you want, so let's say you already have this User model and also want an Admin model with the same authentication stuff, but not confirmation or password recovery. Just follow the same steps:
# Create a migration with the required fields # Create a migration with the required fields

View file

@ -24,7 +24,7 @@ class ConfirmationsController < ApplicationController
if resource.errors.empty? if resource.errors.empty?
sign_in(resource_name, resource) sign_in(resource_name, resource)
set_flash_message :success, :confirmed set_flash_message :success, :confirmed
redirect_to root_path redirect_to home_or_root_path
else else
render :new render :new
end end

View file

@ -30,7 +30,7 @@ class PasswordsController < ApplicationController
if resource.errors.empty? if resource.errors.empty?
sign_in(resource_name, resource) sign_in(resource_name, resource)
set_flash_message :success, :updated set_flash_message :success, :updated
redirect_to root_path redirect_to home_or_root_path
else else
render :edit render :edit
end end

View file

@ -32,8 +32,4 @@ class SessionsController < ApplicationController
:scope => [:devise, :sessions], :default => :unauthenticated) :scope => [:devise, :sessions], :default => :unauthenticated)
end end
def home_or_root_path
home_path = :"#{resource_name}_home_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
end end

View file

@ -42,6 +42,21 @@ module Devise
session[:"#{resource_name}.return_to"] = nil session[:"#{resource_name}.return_to"] = nil
end end
# Checks for the existence of the resource root path. If it exists,
# returns it, otherwise returns the default root_path.
# Used after authenticating a user, confirming it's account or updating
# it's password, so we are able to redirect to scoped root paths.
# Examples (for a user scope):
# map.user_root '/users', :controller => 'users' # creates user_root_path
#
# map.namespace :users do |users|
# users.root # creates user_root_path
# end
def home_or_root_path
home_path = :"#{resource_name}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
# Attempt to find the mapped route for devise based on request path # Attempt to find the mapped route for devise based on request path
def devise_mapping def devise_mapping
@devise_mapping ||= Devise.find_mapping_by_path(request.path) @devise_mapping ||= Devise.find_mapping_by_path(request.path)

View file

@ -11,7 +11,7 @@ ActionController::Routing::Routes.draw do |map|
map.root :controller => :home map.root :controller => :home
map.connect '/admin_area/password/new', :controller => "passwords", :action => "new" map.connect '/admin_area/password/new', :controller => "passwords", :action => "new"
map.admin_home '/admin_area/home', :controller => "admins", :action => "index" map.admin_root '/admin_area/home', :controller => "admins", :action => "index"
map.connect ':controller/:action/:id' map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format' map.connect ':controller/:action/:id.:format'