Updating sessions create to handle authentication, still based on warden strategy
This commit is contained in:
parent
fff46a53eb
commit
643a2ef271
|
@ -1,6 +1,6 @@
|
||||||
class SessionsController < ApplicationController
|
class SessionsController < ApplicationController
|
||||||
before_filter :authenticate!, :except => :new
|
before_filter :authenticate!, :only => :destroy
|
||||||
before_filter :require_no_authentication, :only => :new
|
before_filter :require_no_authentication, :except => :destroy
|
||||||
|
|
||||||
# GET /session/new
|
# GET /session/new
|
||||||
#
|
#
|
||||||
|
@ -10,12 +10,19 @@ class SessionsController < ApplicationController
|
||||||
# POST /session
|
# POST /session
|
||||||
#
|
#
|
||||||
def create
|
def create
|
||||||
redirect_to root_path if authenticated?
|
if authenticate
|
||||||
|
flash[:notice] = I18n.t(:signed_in, :scope => [:devise, :sessions], :default => 'Signed in successfully.')
|
||||||
|
redirect_to root_path
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /session
|
# DELETE /session
|
||||||
#
|
#
|
||||||
def destroy
|
def destroy
|
||||||
redirect_to new_session_path if logout
|
logout
|
||||||
|
flash[:notice] = I18n.t(:signed_out, :scope => [:devise, :sessions], :default => 'Signed out successfully.')
|
||||||
|
redirect_to new_session_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,8 @@ en:
|
||||||
devise:
|
devise:
|
||||||
sessions:
|
sessions:
|
||||||
authentication_failed: 'Invalid email or password.'
|
authentication_failed: 'Invalid email or password.'
|
||||||
|
signed_in: 'Signed in successfully.'
|
||||||
|
signed_out: 'Signed out successfully.'
|
||||||
new:
|
new:
|
||||||
title: 'Sign in'
|
title: 'Sign in'
|
||||||
submit: 'Sign in'
|
submit: 'Sign in'
|
||||||
|
|
|
@ -8,7 +8,7 @@ class MockController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class AuthenticableTest < ActionController::TestCase
|
class ControllerAuthenticableTest < ActionController::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@controller = MockController.new
|
@controller = MockController.new
|
||||||
|
|
|
@ -42,6 +42,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_template 'home/index'
|
assert_template 'home/index'
|
||||||
|
assert_contain 'Signed in successfully'
|
||||||
assert_not_contain 'Sign In'
|
assert_not_contain 'Sign In'
|
||||||
assert warden.authenticated?
|
assert warden.authenticated?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue