added route to grab users profile picture if you know their username

This commit is contained in:
Maxwell Salzberg 2011-09-24 23:33:14 -07:00
parent be00536810
commit 049eb74ab2
3 changed files with 25 additions and 1 deletions

View file

@ -7,7 +7,7 @@ class UsersController < ApplicationController
require File.join(Rails.root, 'lib/diaspora/exporter') require File.join(Rails.root, 'lib/diaspora/exporter')
require File.join(Rails.root, 'lib/collect_user_photos') require File.join(Rails.root, 'lib/collect_user_photos')
before_filter :authenticate_user!, :except => [:new, :create, :public] before_filter :authenticate_user!, :except => [:new, :create, :public, :user_photo]
respond_to :html respond_to :html
@ -119,6 +119,16 @@ class UsersController < ApplicationController
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" ) send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
end end
def user_photo
username = params[:username].split('@')[0]
user = User.find_by_username(username)
if user.present?
redirect_to user.profile.image_url
else
render :nothing => true, :status => 404
end
end
def confirm_email def confirm_email
if current_user.confirm_email(params[:token]) if current_user.confirm_email(params[:token])
flash[:notice] = I18n.t('users.confirm_email.email_confirmed', :email => current_user.email) flash[:notice] = I18n.t('users.confirm_email.email_confirmed', :email => current_user.email)

View file

@ -52,6 +52,8 @@ Diaspora::Application.routes.draw do
delete "tag_followings" => "tag_followings#destroy" delete "tag_followings" => "tag_followings#destroy"
end end
get '/user_photo/:username' => 'users#user_photo'
# get "tag_followings" => "tag_followings#index", :as => 'tag_followings' # get "tag_followings" => "tag_followings#index", :as => 'tag_followings'
get 'tags/:name' => 'tags#show', :as => 'tag' get 'tags/:name' => 'tags#show', :as => 'tag'

View file

@ -26,6 +26,18 @@ describe UsersController do
end end
end end
describe 'user_photo' do
it 'should return the url of the users profile photo' do
get :user_photo, :username => @user.username
response.should redirect_to(@user.profile.image_url)
end
it 'should 404 if no user is found' do
get :user_photo, :username => 'none'
response.should_not be_success
end
end
describe '#public' do describe '#public' do
it 'renders xml if atom is requested' do it 'renders xml if atom is requested' do
sm = Factory(:status_message, :public => true, :author => @user.person) sm = Factory(:status_message, :public => true, :author => @user.person)