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
|
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
|
protected
|
||||||
def enqueue_update
|
def enqueue_update
|
||||||
if current_user
|
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
|
Resque.enqueue(Job::UpdateServiceUsers, s.id) if s.respond_to? :save_friends
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,15 @@
|
||||||
|
|
||||||
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
# 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.
|
# 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|
|
Devise.setup do |config|
|
||||||
# Configure the e-mail address which will be shown in DeviseMailer.
|
# Configure the e-mail address which will be shown in DeviseMailer.
|
||||||
if AppConfig[:smtp_sender_address]
|
if AppConfig[:smtp_sender_address]
|
||||||
|
|
@ -11,9 +20,9 @@ Devise.setup do |config|
|
||||||
else
|
else
|
||||||
unless Rails.env == 'test'
|
unless Rails.env == 'test'
|
||||||
Rails.logger.warn("No smtp sender address set, mail may fail.")
|
Rails.logger.warn("No smtp sender address set, mail may fail.")
|
||||||
puts "WARNING: No smtp sender address set, mail may fail."
|
puts "WARNING: No smtp sender address set, mail may fail."
|
||||||
end
|
end
|
||||||
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
# ==> ORM configuration
|
# ==> ORM configuration
|
||||||
|
|
@ -27,7 +36,7 @@ Devise.setup do |config|
|
||||||
# authenticating an user, both parameters are required. Remember that those
|
# authenticating an user, both parameters are required. Remember that those
|
||||||
# parameters are used only when authenticating and not when retrieving from
|
# parameters are used only when authenticating and not when retrieving from
|
||||||
# session. If you need permissions, you should implement that in a before filter.
|
# 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.
|
# Tell if authentication through request.params is enabled. True by default.
|
||||||
# config.params_authenticatable = true
|
# config.params_authenticatable = true
|
||||||
|
|
@ -56,7 +65,7 @@ Devise.setup do |config|
|
||||||
# Time interval where the invitation token is valid (default: 0).
|
# Time interval where the invitation token is valid (default: 0).
|
||||||
# If invite_for is 0 or nil, the invitation will never expire.
|
# If invite_for is 0 or nil, the invitation will never expire.
|
||||||
# config.invite_for = 2.weeks
|
# config.invite_for = 2.weeks
|
||||||
|
|
||||||
# ==> Configuration for :confirmable
|
# ==> Configuration for :confirmable
|
||||||
# The time you want to give your user to confirm his account. During this time
|
# The time you want to give your user to confirm his account. During this time
|
||||||
# he will be able to access your application without confirming. Default is nil.
|
# he will be able to access your application without confirming. Default is nil.
|
||||||
|
|
@ -130,6 +139,7 @@ Devise.setup do |config|
|
||||||
# If you have any extra navigational formats, like :iphone or :mobile, you
|
# If you have any extra navigational formats, like :iphone or :mobile, you
|
||||||
# should add them to the navigational formats lists. Default is [:html]
|
# should add them to the navigational formats lists. Default is [:html]
|
||||||
# config.navigational_formats = [:html, :iphone]
|
# config.navigational_formats = [:html, :iphone]
|
||||||
|
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
|
||||||
|
|
||||||
# ==> Warden configuration
|
# ==> Warden configuration
|
||||||
# If you want to use other strategies, that are not (yet) supported by Devise,
|
# If you want to use other strategies, that are not (yet) supported by Devise,
|
||||||
|
|
|
||||||
|
|
@ -24,23 +24,39 @@ describe SessionsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#create" do
|
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"}}
|
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
|
||||||
response.should redirect_to root_path
|
response.should redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redirects to / for a mobile user" do
|
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'
|
@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"}}
|
post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}}
|
||||||
response.should redirect_to root_path
|
response.should redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'queues up an update job' do
|
it 'queues up an update job' do
|
||||||
service = Services::Facebook.new(:access_token => "yeah")
|
service = Services::Facebook.new(:access_token => "yeah")
|
||||||
@user.services << service
|
@user.services << service
|
||||||
@user.save
|
|
||||||
|
|
||||||
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, service.id)
|
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
|
end
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue