Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Better implementation of redirecting to stored URI - committed to nif…
Browse files Browse the repository at this point in the history
…ty_generators plugin as well
  • Loading branch information
James Miller committed May 13, 2009
1 parent 5872c15 commit 3240273
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 0 additions & 5 deletions app/controllers/application_controller.rb
Expand Up @@ -20,9 +20,4 @@ def admin?
end
helper_method :admin?

def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end

end
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Expand Up @@ -11,7 +11,7 @@ def create
subscriber = Subscriber.authenticate(params[:login], params[:password])
if subscriber
session[:subscriber_id] = subscriber.id
redirect_back_or_default('/')
redirect_to_target_or_default(root_url)
else
flash.now[:warning] = "Invalid login or password."
render :action => 'new'
Expand Down
11 changes: 8 additions & 3 deletions lib/authentication.rb
Expand Up @@ -13,15 +13,20 @@ def logged_in?

def login_required
unless logged_in?
flash[:notice] = "You need to login or create an account to continue."
store_location
flash[:error] = "You must first log in or sign up before accessing this page."
store_target_location
redirect_to login_url
end
end

def redirect_to_target_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end

private

def store_location
def store_target_location
session[:return_to] = request.request_uri
end
end
1 change: 1 addition & 0 deletions tmp/.gitignore
@@ -0,0 +1 @@
restart.txt

0 comments on commit 3240273

Please sign in to comment.