Tell devise that :mobile is a navigational format.
This commit is contained in:
parent
fbf486dae6
commit
43ab8cfcfa
3 changed files with 37 additions and 21 deletions
|
|
@ -6,22 +6,12 @@ class SessionsController < Devise::SessionsController
|
|||
|
||||
after_filter :enqueue_update, :only => :create
|
||||
|
||||
def create
|
||||
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
|
||||
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
||||
sign_in(resource_name, resource)
|
||||
redirect_loc = redirect_location(resource_name, resource)
|
||||
respond_with resource, :location => redirect_loc do |format|
|
||||
format.mobile { redirect_to root_path }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def enqueue_update
|
||||
if current_user
|
||||
current_user.services.each{|s|
|
||||
current_user.services.each do |s|
|
||||
Resque.enqueue(Job::UpdateServiceUsers, s.id) if s.respond_to? :save_friends
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,15 @@
|
|||
|
||||
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
||||
# four configuration values can also be set straight in your models.
|
||||
|
||||
class ActionController::Responder
|
||||
def to_mobile
|
||||
default_render
|
||||
rescue ActionView::MissingTemplate => e
|
||||
navigation_behavior(e)
|
||||
end
|
||||
end
|
||||
|
||||
Devise.setup do |config|
|
||||
# Configure the e-mail address which will be shown in DeviseMailer.
|
||||
if AppConfig[:smtp_sender_address]
|
||||
|
|
@ -27,7 +36,7 @@ Devise.setup do |config|
|
|||
# authenticating an user, both parameters are required. Remember that those
|
||||
# parameters are used only when authenticating and not when retrieving from
|
||||
# session. If you need permissions, you should implement that in a before filter.
|
||||
config.authentication_keys = [ :username ]
|
||||
config.authentication_keys = [:username]
|
||||
|
||||
# Tell if authentication through request.params is enabled. True by default.
|
||||
# config.params_authenticatable = true
|
||||
|
|
@ -130,6 +139,7 @@ Devise.setup do |config|
|
|||
# If you have any extra navigational formats, like :iphone or :mobile, you
|
||||
# should add them to the navigational formats lists. Default is [:html]
|
||||
# config.navigational_formats = [:html, :iphone]
|
||||
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
|
||||
|
||||
# ==> Warden configuration
|
||||
# If you want to use other strategies, that are not (yet) supported by Devise,
|
||||
|
|
|
|||
|
|
@ -24,23 +24,39 @@ describe SessionsController do
|
|||
end
|
||||
|
||||
describe "#create" do
|
||||
it "redirects to / for a normal user" do
|
||||
it "redirects to / for a non-mobile user" do
|
||||
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
|
||||
response.should redirect_to root_path
|
||||
end
|
||||
|
||||
it "redirects to / for a mobile user" do
|
||||
@request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'
|
||||
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
|
||||
response.should redirect_to root_path
|
||||
end
|
||||
|
||||
it 'queues up an update job' do
|
||||
service = Services::Facebook.new(:access_token => "yeah")
|
||||
@user.services << service
|
||||
@user.save
|
||||
|
||||
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, service.id)
|
||||
post :create, {"user"=>{"remember_me"=>"0", "username"=> @user.username,
|
||||
"password"=>"evankorth"}}
|
||||
|
||||
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "#destroy" do
|
||||
before do
|
||||
sign_in :user, @user
|
||||
end
|
||||
it "redirects to / for a non-mobile user" do
|
||||
delete :destroy
|
||||
response.should redirect_to root_path
|
||||
end
|
||||
|
||||
it "redirects to / for a mobile user" do
|
||||
@request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7'
|
||||
delete :destroy
|
||||
response.should redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue