Skip to content

Commit

Permalink
Naming some routes; making all the redirects use route helpers consis…
Browse files Browse the repository at this point in the history
…tently
  • Loading branch information
carols10cents committed Feb 18, 2012
1 parent a22228c commit 977e1c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def auth
unless @auth = Authorization.find_from_hash(auth)
if logged_in?
Authorization.create_from_hash!(auth, root_url, current_user)
redirect_to [:edit, current_user] and return
redirect_to edit_user_path(current_user)
return
else

# This situation here really sucks. I'd like to do something better,
Expand All @@ -44,7 +45,6 @@ def auth
end

redirect_to new_user_path

return
end
end
Expand Down Expand Up @@ -90,6 +90,6 @@ def destroy
session[:user_id] = user.id
end

redirect_to [:edit, user]
redirect_to edit_user_path(user)
end
end
44 changes: 22 additions & 22 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,11 @@ def create_from_email
end
end

# This is pretty much the same thing as /feeds/your_feed_id, but we
# This is pretty much the same thing as /feeds/your_feed_id.atom, but we
# wanted to have a really nice URL for it, and not just the ugly one.
# Since it's only two lines, we don't bother to do a redirect, and
# it's arguably better to display them as two different resources.
# Whatevs.
# Except we ARE doing a redirect??? /me shakes fist at steve
def feed
if @user
redirect_to "/feeds/#{@user.feed.id}.atom"
redirect_to feed_path(@user.feed, :format => :atom)
else
render :file => "#{Rails.root}/public/404.html", :status => 404
end
Expand All @@ -118,8 +114,10 @@ def feed
def following
if @user.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404
elsif @user.username != params[:id] # case difference
redirect_to "/users/#{@user.username}/following"
# If the username's case entered in the URL is different than the case
# specified by that user, redirect to the case that the user prefers
elsif @user.username != params[:id]
redirect_to following_path(@user.username)
else
set_params_page

Expand Down Expand Up @@ -149,8 +147,10 @@ def following
def followers
if @user.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404
elsif @user.username != params[:id] # case difference
redirect_to "/users/#{@user.username}/followers"
# If the username's case entered in the URL is different than the case
# specified by that user, redirect to the case that the user prefers
elsif @user.username != params[:id]
redirect_to followers_path(@user.username)
else
set_params_page

Expand Down Expand Up @@ -183,17 +183,17 @@ def confirm_email
user = User.first(:perishable_token => params[:token])
if user.nil?
flash[:notice] = "Can't find User Account for this link."
redirect_to "/"
redirect_to root_path
elsif user.token_expired?
flash[:notice] = "Your link is no longer valid, please request a new one."
redirect_to "/"
redirect_to root_path
else
user.email_confirmed = true
user.reset_perishable_token
# Register a session for the user
session[:user_id] = user.id
flash[:notice] = "Email successfully confirmed."
redirect_to "/"
redirect_to root_path
end
end

Expand All @@ -217,7 +217,7 @@ def forgot_password_create
Notifier.send_forgot_password_notification(user.email, user.create_token)
# Redirect to try to avoid repost issues
session[:fp_email] = user.email
redirect_to '/forgot_password_confirm'
redirect_to forgot_password_confirm_path
end
end

Expand All @@ -230,7 +230,7 @@ def forgot_password_confirm

def reset_password_new
if not logged_in?
redirect_to "/forgot_password"
redirect_to forgot_password_path
else
render "login/password_reset"
end
Expand All @@ -254,20 +254,20 @@ def reset_password_create

if params[:password].size == 0
flash[:notice] = "Password must be present"
redirect_to "/reset_password/#{params[:token]}"
redirect_to reset_password_path(params[:token])
return
end

if params[:password] != params[:password_confirm]
flash[:notice] = "Passwords do not match"
redirect_to "/reset_password/#{params[:token]}"
redirect_to reset_password_path(params[:token])
return
end

if user.email.nil?
if params[:email].empty?
flash[:notice] = "Email must be provided"
redirect_to "/reset_password/#{params[:token]}"
redirect_to reset_password_path(params[:token])
return
else
user.email = params[:email]
Expand All @@ -277,9 +277,9 @@ def reset_password_create
user.password = params[:password]
user.save
flash[:notice] = "Password successfully set"
redirect_to "/"
redirect_to root_path
else
redirect_to "/forgot_password"
redirect_to forgot_password_path
end
end

Expand All @@ -290,10 +290,10 @@ def reset_password_with_token
user = User.first(:perishable_token => params[:token])
if user.nil? || user.token_expired?
flash[:notice] = "Your link is no longer valid, please request a new one."
redirect_to "/forgot_password"
redirect_to forgot_password_path
else
@token = params[:token]
@user = user
@user = user
render "login/password_reset"
end
end
Expand Down
10 changes: 5 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
match "users/:id/feed", :to => "users#feed", :as => "user_feed", :constraints => { :id => /[^\/]+/ }

# other new route?
match 'users/:id/followers', :to => "users#followers", :constraints => { :id => /[^\/]+/ }
match 'users/:id/following', :to => "users#following", :constraints => { :id => /[^\/]+/ }
match 'users/:id/followers', :to => "users#followers", :constraints => { :id => /[^\/]+/ }, :as => "followers"
match 'users/:id/following', :to => "users#following", :constraints => { :id => /[^\/]+/ }, :as => "following"
match 'confirm_email/:token', :to => "users#confirm_email"
match 'forgot_password', :to => "users#forgot_password_new", :via => :get
match 'forgot_password', :to => "users#forgot_password_new", :via => :get, :as => "forgot_password"
match 'forgot_password', :to => "users#forgot_password_create", :via => :post
match 'forgot_password_confirm', :to => "users#forgot_password_confirm", :via => :get
match 'forgot_password_confirm', :to => "users#forgot_password_confirm", :via => :get, :as => "forgot_password_confirm"
match 'reset_password', :to => "users#reset_password_new", :via => :get
match 'reset_password', :to => "users#reset_password_create", :via => :post
match 'reset_password/:token', :to => "users#reset_password_with_token", :via => :get
match 'reset_password/:token', :to => "users#reset_password_with_token", :via => :get, :as => "reset_password"

# Updates
resources :updates, :only => [:index, :show, :create, :destroy]
Expand Down

0 comments on commit 977e1c5

Please sign in to comment.