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
|
||||
before_filter :authenticate!, :except => :new
|
||||
before_filter :require_no_authentication, :only => :new
|
||||
before_filter :authenticate!, :only => :destroy
|
||||
before_filter :require_no_authentication, :except => :destroy
|
||||
|
||||
# GET /session/new
|
||||
#
|
||||
|
@ -10,12 +10,19 @@ class SessionsController < ApplicationController
|
|||
# POST /session
|
||||
#
|
||||
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
|
||||
|
||||
# DELETE /session
|
||||
#
|
||||
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
|
||||
|
|
|
@ -2,6 +2,8 @@ en:
|
|||
devise:
|
||||
sessions:
|
||||
authentication_failed: 'Invalid email or password.'
|
||||
signed_in: 'Signed in successfully.'
|
||||
signed_out: 'Signed out successfully.'
|
||||
new:
|
||||
title: 'Sign in'
|
||||
submit: 'Sign in'
|
||||
|
|
|
@ -8,7 +8,7 @@ class MockController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
class AuthenticableTest < ActionController::TestCase
|
||||
class ControllerAuthenticableTest < ActionController::TestCase
|
||||
|
||||
def setup
|
||||
@controller = MockController.new
|
||||
|
|
|
@ -42,6 +42,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|||
|
||||
assert_response :success
|
||||
assert_template 'home/index'
|
||||
assert_contain 'Signed in successfully'
|
||||
assert_not_contain 'Sign In'
|
||||
assert warden.authenticated?
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue