Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

redirect user back to target location after signing in

  • Loading branch information...
commit 6819c7fc620765b244d025bfe6d40eb9c7ac13b2 1 parent 1c61f91
@ryanb authored
View
8 app/controllers/authentications_controller.rb
@@ -10,8 +10,8 @@ def create
authentication.user.apply_omniauth(omniauth)
authentication.user.save!
remember_user(authentication.user)
- flash[:notice] = "Signed in successfully."
- redirect_to root_url
+ flash[:notice] = "Signed in as #{authentication.user.username}"
+ redirect_to_target_or_default root_url
else
user = current_user_or_guest
user.authentications.create!(:provider => omniauth['provider'], :uid => omniauth['uid'])
@@ -20,9 +20,9 @@ def create
user.guest = false
if user.save
if was_guest
- flash[:notice] = "Signed in successfully."
+ flash[:notice] = "Signed in as #{user.username}."
remember_user(user)
- redirect_to root_url
+ redirect_to_target_or_default root_url
else
flash[:notice] = "Authentication successful."
redirect_to edit_current_user_url
View
2  app/controllers/games_controller.rb
@@ -20,7 +20,7 @@ def new
@game = Game.new
if params[:username]
if guest?
- flash.now[:alert] = "You must first sign in before you can challenge another player to a game."
+ login_required("You must first sign in before you can challenge another player to a game.")
else
@game.chosen_opponent = "user"
@game.opponent_username = params[:username]
View
4 lib/controller_authentication.rb
@@ -48,9 +48,9 @@ def guest?
current_user.nil? || current_user.guest?
end
- def login_required
+ def login_required(message = "You must first log in or sign up before accessing this page.")
unless logged_in?
- flash[:alert] = "You must first log in or sign up before accessing this page."
+ flash[:alert] = message
store_target_location
redirect_to signin_url
end
View
10 spec/controllers/games_controller_spec.rb
@@ -19,6 +19,11 @@
response.should render_template(:new)
end
+ it "new action should redirect user to signin when trying to challenge username" do
+ get :new, :username => "foo"
+ response.should redirect_to(signin_url)
+ end
+
it "create action should render new template when model is invalid" do
Game.any_instance.stubs(:valid?).returns(false)
post :create
@@ -49,6 +54,11 @@
@controller.stubs(:current_user).returns(@user)
end
+ it "new action should render new template with custom username" do
+ get :new, :username => "foo"
+ response.should render_template(:new)
+ end
+
it "create action should send email to opponent user" do
opponent = Factory(:user, :email_on_invitation => true)
post :create, :game => { :chosen_opponent => "user", :opponent_username => opponent.username, :chosen_color => "black" }
Please sign in to comment.
Something went wrong with that request. Please try again.