Skip to content

Commit

Permalink
Merge remote-tracking branch 'nashby/refactor'
Browse files Browse the repository at this point in the history
Conflicts:
	app/models/user.rb
  • Loading branch information
carols10cents committed Feb 18, 2012
2 parents b6d5d27 + fa0bcfe commit a22228c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 44 deletions.
13 changes: 7 additions & 6 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def auth
unless @auth = Authorization.find_from_hash(auth)
if logged_in?
Authorization.create_from_hash!(auth, root_url, current_user)
redirect_to "/users/#{current_user.username}/edit" and return
redirect_to [:edit, current_user] and return
else

# This situation here really sucks. I'd like to do something better,
Expand All @@ -43,7 +43,7 @@ def auth
flash[:error] = "Sorry, someone else has that username. Please pick another."
end

redirect_to '/users/new'
redirect_to new_user_path

return
end
Expand All @@ -61,7 +61,8 @@ def auth
session[:user_id] = @auth.user.id

flash[:notice] = "You're now logged in."
redirect_to '/'

redirect_to root_path
end

def failure
Expand All @@ -82,13 +83,13 @@ def failure

# This lets someone remove a particular Authorization from their account.
def destroy
user = User.first(:username => params[:username])
if user
if user = User.first(:username => params[:username])
auth = Authorization.first(:provider => params[:provider], :user_id => user.id)
auth.destroy if auth
# Without re-setting the session[:user_id] we're logged out
session[:user_id] = user.id
end
redirect_to "/users/#{params[:username]}/edit"

redirect_to [:edit, user]
end
end
2 changes: 1 addition & 1 deletion app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def show
feed = Feed.first :id => params[:id]
if feed.local?
# Redirect to the local profile page
redirect_to "/users/#{feed.author.username}"
redirect_to user_path(feed.author)
else
# Why not...
# While weird, to render the view for this model, one
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create
@user.save
session[:user_id] = @user.id
flash[:notice] = "Thanks for signing up!"
redirect_to "/"
redirect_to root_path
return
else
@user.errors.add(:password, "can't be empty")
Expand All @@ -39,7 +39,7 @@ def create
if user = User.authenticate(params[:username], params[:password])
session[:user_id] = user.id
flash[:notice] = "Login successful."
redirect_to "/"
redirect_to root_path
return
end
flash[:error] = "The password given for username \"#{params[:username]}\" is incorrect.
Expand All @@ -52,7 +52,7 @@ def create
def destroy
session[:user_id] = nil
flash[:notice] = "You've been logged out."
redirect_to '/'
redirect_to root_path
end

end
32 changes: 16 additions & 16 deletions app/controllers/subscriptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
class SubscriptionsController < ApplicationController
def show

feed = Feed.first :id => params[:id]
before_filter :find_feed, :except => :create

def show
if params['hub.challenge']
sub = OSub::Subscription.new(request.url, feed.url, nil, feed.verify_token)
sub = OSub::Subscription.new(request.url, @feed.url, nil, @feed.verify_token)

# perform the hub's challenge
respond = sub.perform_challenge(params['hub.challenge'])

# verify that the random token is the same as when we
# subscribed with the hub initially and that the topic
# url matches what we expect
verified = params['hub.topic'] == feed.url
if verified and sub.verify_subscription(params['hub.verify_token'])
verified = params['hub.topic'] == @feed.url
if verified && sub.verify_subscription(params['hub.verify_token'])
render :text => respond[:body], :status => respond[:status]
else
# if the verification fails, the specification forces us to
Expand All @@ -30,19 +29,17 @@ def show
def destroy
require_login! :return => request.referrer

feed = Feed.first :id => params[:id]

@author = feed.author
@author = @feed.author

if @author.user == current_user
# You're not allowed to follow yourself.
redirect_to request.referrer
elsif !current_user.following_url? feed.url
elsif !current_user.following_url? @feed.url
# If we're not following them, noop.
flash[:notice] = "You're not following #{@author.username}."
redirect_to request.referrer
else
current_user.unfollow! feed
current_user.unfollow! @feed

flash[:notice] = "No longer following #{@author.username}."
redirect_to request.referrer
Expand All @@ -52,12 +49,9 @@ def destroy
# subscriber receives updates
# should be 'put', PuSH sucks at REST
def post_update
feed = Feed.first :id => params[:id]
if feed.nil?
raise ActionController::RoutingError.new('Not Found')
end
raise ActionController::RoutingError.new('Not Found') if @feed.nil?

feed.update_entries(request.body.read, request.url, feed.url, request.env['HTTP_X_HUB_SIGNATURE'])
@feed.update_entries(request.body.read, request.url, @feed.url, request.env['HTTP_X_HUB_SIGNATURE'])
render :nothing => true
end

Expand Down Expand Up @@ -96,4 +90,10 @@ def create
flash[:notice] = "Now following #{f.author.username}."
redirect_to request.referrer
end

private

def find_feed
@feed = Feed.first :id => params[:id]
end
end
33 changes: 15 additions & 18 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class UsersController < ApplicationController
before_filter :find_user, :only => [:show, :edit, :update, :feed, :following, :followers]

def index
set_params_page
Expand All @@ -11,28 +12,24 @@ def index
end

def show
user = User.find_by_case_insensitive_username(params[:id])

if user.nil?
if @user.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404
elsif user.username != params[:id] # case difference
redirect_to "/users/#{user.username}"
elsif @user.username != params[:id] # case difference
redirect_to user_path(@user)
else
set_params_page

@author = user.author
@updates = user.updates
@author = @user.author
@updates = @user.updates
@updates = @updates.paginate(:page => params[:page], :per_page => params[:per_page])

set_pagination_buttons(@updates)

headers['Link'] = "<#{user_xrd_path(user.author.username)}>; rel=\"lrdd\"; type=\"application/xrd+xml\""
headers['Link'] = "<#{user_xrd_path(@user.author)}>; rel=\"lrdd\"; type=\"application/xrd+xml\""
end
end

def edit
@user = User.find_by_case_insensitive_username(params[:id])

# While it might be cool to edit other people's profiles, we probably
# shouldn't let you do that. We're no fun.
if @user == current_user
Expand All @@ -43,7 +40,6 @@ def edit
end

def update
@user = User.find_by_case_insensitive_username(params[:id])
if @user == current_user
response = @user.edit_user_profile(params)
if response == true
Expand Down Expand Up @@ -110,9 +106,8 @@ def create_from_email
# Whatevs.
# Except we ARE doing a redirect??? /me shakes fist at steve
def feed
user = User.find_by_case_insensitive_username(params[:id])
if user
redirect_to "/feeds/#{user.feed.id}.atom"
if @user
redirect_to "/feeds/#{@user.feed.id}.atom"
else
render :file => "#{Rails.root}/public/404.html", :status => 404
end
Expand All @@ -121,8 +116,6 @@ def feed
# Who do you think is a really neat person? This page will show it to the
# world, so pick wisely!
def following
@user = User.find_by_case_insensitive_username(params[:id])

if @user.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404
elsif @user.username != params[:id] # case difference
Expand Down Expand Up @@ -154,8 +147,6 @@ def following
# This shows off how cool you are: I hope you've got the biggest number of
# followers. Only one way to find out...
def followers
@user = User.find_by_case_insensitive_username(params[:id])

if @user.nil?
render :file => "#{Rails.root}/public/404.html", :status => 404
elsif @user.username != params[:id] # case difference
Expand Down Expand Up @@ -306,4 +297,10 @@ def reset_password_with_token
render "login/password_reset"
end
end

private

def find_user
@user = User.find_by_case_insensitive_username(params[:id])
end
end
4 changes: 4 additions & 0 deletions app/models/author.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ def normalize_domain
self.domain = norm
end

def to_param
username
end

def self.search(params = {})
if params[:search] && !params[:search].empty?
Author.where(:username => /#{params[:search]}/i)
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ def token_expired?
self.perishable_token_set.to_time < 2.days.ago
end

def to_param
username
end

private

def create_feed
Expand Down

0 comments on commit a22228c

Please sign in to comment.