Created
March 6, 2012 09:12
-
-
Save abradburne/1985133 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def require_user | |
| unless current_user_session | |
| respond_to do |format| | |
| format.html { redirect_to '/hi' } | |
| format.json do | |
| headers["WWW-Authenticate"] = %(Basic realm="Web Password") | |
| render :json => {'error' => 'Could not authenticate you.'}, :status => :unauthorized | |
| end | |
| end | |
| return false | |
| end | |
| end | |
| def require_no_user | |
| if current_user | |
| respond_to do |format| | |
| format.html do | |
| store_location | |
| flash[:notice] = "You must be logged out to access this page" | |
| redirect_to '/' | |
| return false | |
| end | |
| format.json do | |
| return true | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment