Created
October 20, 2010 06:22
-
-
Save baileylo/635885 to your computer and use it in GitHub Desktop.
Removed unused functions, fixed redirects, and much much less awesomeness
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
class UsersController < ApplicationController | |
# GET /users/1 | |
def show | |
@user = User.find(params[:id]) | |
end | |
# GET /users/new | |
def new | |
@user = User.new | |
if current_user | |
redirect_to(homepage_url, :notice => 'Already registered') | |
end | |
end | |
# GET /users/1/edit | |
def edit | |
is_user | |
end | |
# POST /users | |
# POST /users.xml | |
def create | |
@user = User.new(params[:user]) | |
@user_session = UserSession.new(params[:user]) | |
respond_to do |format| | |
if @user.save && @user_session.save | |
format.html { redirect_to(homepage_url, :notice => 'Registration successfull.') } | |
else | |
format.html { render :action => "new" } | |
end | |
end | |
end | |
# PUT /users/1 | |
def update | |
is_user | |
respond_to do |format| | |
if @user.update_attributes(params[:user]) | |
format.html { redirect_to(@user, :notice => 'User was successfully updated.') } | |
else | |
format.html { render :action => "edit" } | |
end | |
end | |
end | |
private | |
def is_user | |
if User.exists?(params[:id]) | |
@user = User.find(params[:id]); | |
if !current_user || current_user.id != @user.id | |
redirect_to(homepage_url, :notice =>"You do not have access to that page") | |
end | |
else | |
redirect_to(homepage_url, :notice =>"You do not have access to that page") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment