allow login via private token only for atom feeds
This commit is contained in:
parent
f8f6ff065e
commit
cc3c6ad0ef
2 changed files with 16 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
before_filter :reject_blocked!
|
before_filter :reject_blocked!
|
||||||
before_filter :set_current_user_for_mailer
|
before_filter :set_current_user_for_mailer, :check_token_auth
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
helper_method :abilities, :can?
|
helper_method :abilities, :can?
|
||||||
|
|
||||||
|
@ -17,9 +17,16 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
def check_token_auth
|
||||||
|
# Redirect to login page if not atom feed
|
||||||
|
if params[:private_token].present? && params[:format] != 'atom'
|
||||||
|
redirect_to new_user_session_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def reject_blocked!
|
def reject_blocked!
|
||||||
if current_user && current_user.blocked
|
if current_user && current_user.blocked
|
||||||
sign_out current_user
|
sign_out current_user
|
||||||
flash[:alert] = "Your account was blocked"
|
flash[:alert] = "Your account was blocked"
|
||||||
redirect_to new_user_session_path
|
redirect_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,13 @@ describe "Projects" do
|
||||||
visit projects_path(:atom, :private_token => @user.private_token)
|
visit projects_path(:atom, :private_token => @user.private_token)
|
||||||
page.body.should have_selector("feed title")
|
page.body.should have_selector("feed title")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not render projects page via private token" do
|
||||||
|
logout
|
||||||
|
|
||||||
|
visit projects_path(:private_token => @user.private_token)
|
||||||
|
current_path.should == new_user_session_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "GET /projects/new" do
|
describe "GET /projects/new" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue