所以,我嘗試使用的認證令牌來直接登錄鏈接,但我發現在我的服務器日誌Filter chain halted as :after_token_authentication rendered or redirected
直接鏈接登錄停止
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :store_location
before_filter :authenticate_user!
before_filter :after_token_authentication
check_authorization :unless => :devise_controller?
rescue_from CanCan::AccessDenied do |exception|
session[:previous_url] = nil
redirect_to root_url
end
def store_location
# reset_session
# store last url - this is needed for post-login redirect to whatever the user last visited.
if (request.fullpath != "/user/sign_in" && \
request.fullpath != "/user/sign_up" && \
request.fullpath != "/user/password" && \
!request.fullpath.include?("/user") && \
!request.fullpath.include?("/admin") && \
!request.xhr?) # don't store ajax calls
session[:previous_url] = request.fullpath
end
end
def after_sign_in_path_for(resource)
if current_user.admin?
admin_dashboard_path
elsif current_user.contractor?
if current_user.contractor.business_name == 'Test Devise'
'url'
else
contractor_dashboard_path
end
else
session[:previous_url] || homeowner_service_requests_path
end
end
#generates 6-digit random password (a-z, 0-9) for sending to users when BuildZoom creates user account after they express interest in a service request, leave a review
def generate_temporary_password
rand(36**6).to_s(36)
end
protected
def after_token_authentication
if params[:authentication_key].present?
@user = User.find_by_authentication_token(params[:authentication_key])
sign_in @user if @user
welcome = @user.approved.eql?(7) and @user.type.eql?(2)
@user.approved = 0
@user.save
unless welcome
redirect_to root_path
else
redirect_to contractor_welcome_path
end
elsif params[:auth_token].present? && params[:location] == "galleries"
@current_user = User.find_by_authentication_token(params[:auth_token])
sign_in @current_user if @current_user
@current_user.approved = 0
@current_user.save
debugger
redirect_to contractor_list_galleries_path
end
end
def after_sign_out_path_for(resource)
'url'
end
end
這裏是服務器日誌:
Started GET "/?auth_token=uN8QFMsocpDyhWKCx9QN&location=galleries" for 127.0.0.1 at 2013-09-20 22:38:37 -0700
Processing by PagesController#home as HTML
Parameters: {"auth_token"=>"uN8QFMsocpDyhWKCx9QN", "location"=>"galleries"}
Geokit is using the domain:
User Load (189.2ms) SELECT `users`.* FROM `users` WHERE `users`.`authentication_token` = 'uN8QFMsocpDyhWKCx9QN' LIMIT 1
(109.5ms) BEGIN
(111.7ms) UPDATE `users` SET `last_sign_in_at` = '2013-09-21 05:38:28', `current_sign_in_at` = '2013-09-21 05:38:38', `sign_in_count` = 61, `updated_at` = '2013-09-21 05:38:38' WHERE `users`.`uid` = 149407
(95.6ms) COMMIT
User Load (184.3ms) SELECT `users`.* FROM `users` WHERE `users`.`authentication_token` = 'uN8QFMsocpDyhWKCx9QN' LIMIT 1
(93.3ms) BEGIN
(109.5ms) COMMIT
Redirected to http://0.0.0.0:3000/contractor/galleries
Filter chain halted as :after_token_authentication rendered or redirected
Completed 302 Found in 10884ms (ActiveRecord: 893.2ms)
Started GET "/contractor/galleries" for 127.0.0.1 at 2013-09-20 22:38:48 -0700
Processing by Contractor::ContractorGalleriesController#index as HTML
Geokit is using the domain:
Completed 401 Unauthorized in 1ms
Started GET "/contractor/galleries" for 127.0.0.1 at 2013-09-20 22:38:49 -0700
Processing by Contractor::ContractorGalleriesController#index as HTML
Geokit is using the domain:
Completed 401 Unauthorized in 1ms
Started GET "/user/sign_in" for 127.0.0.1 at 2013-09-20 22:38:49 -0700
Processing by Devise::SessionsController#new as HTML
Geokit is using the domain:
Rendered devise/shared/_links.erb (0.5ms)
Rendered devise/sessions/new.html.erb within layouts/application (3.7ms)
Rendered shared/_mixpanel.html.erb (0.2ms)
Rendered layouts/_head.html.erb (12.4ms)
Rendered layouts/_navigation.html.erb (0.6ms)
Rendered layouts/_messages.html.erb (0.1ms)
Rendered shared/_olark (0.0ms)
Rendered layouts/_footer.html.erb (1.2ms)
Completed 200 OK in 64ms (Views: 62.5ms | ActiveRecord: 0.0ms)
Started GET "/user/sign_in" for 127.0.0.1 at 2013-09-20 22:38:49 -0700
Processing by Devise::SessionsController#new as HTML
Geokit is using the domain:
Rendered devise/shared/_links.erb (0.5ms)
Rendered devise/sessions/new.html.erb within layouts/application (4.8ms)
Rendered shared/_mixpanel.html.erb (0.1ms)
Rendered layouts/_head.html.erb (11.5ms)
Rendered layouts/_navigation.html.erb (0.6ms)
Rendered layouts/_messages.html.erb (0.0ms)
Rendered shared/_olark (0.0ms)
Rendered layouts/_footer.html.erb (1.1ms)
Completed 200 OK in 113ms (Views: 111.4ms | ActiveRecord: 0.0ms)
能否請您檢查@ current_user.save將返回true或false值,如果是假的,然後檢查爲什麼它返回false。這應該是真的,那麼它會起作用。 –