2014-11-02 08:57:37 -08:00
|
|
|
class UserController < ApplicationController
|
2015-01-02 12:34:56 -08:00
|
|
|
before_filter :authenticate_user!, only: %w(edit update privacy)
|
2014-12-29 02:21:43 -08:00
|
|
|
|
2014-11-02 08:57:37 -08:00
|
|
|
def show
|
2014-12-21 06:32:49 -08:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-11-12 11:40:24 -08:00
|
|
|
@answers = @user.answers.reverse_order.paginate(page: params[:page])
|
2014-12-08 06:23:04 -08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
2014-11-02 08:57:37 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2014-11-03 04:21:41 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-12-29 02:21:43 -08:00
|
|
|
user_attributes = params.require(:user).permit(:display_name, :profile_picture, :motivation_header, :website,
|
2014-12-29 05:52:06 -08:00
|
|
|
:location, :bio, :crop_x, :crop_y, :crop_w, :crop_h)
|
2014-12-29 05:54:32 -08:00
|
|
|
if current_user.update_attributes(user_attributes)
|
|
|
|
text = 'Your profile has been updated!'
|
|
|
|
text += ' It might take a few minutes until your new profile picture is shown everywhere.' if user_attributes[:profile_picture]
|
|
|
|
flash[:success] = text
|
|
|
|
else
|
2014-12-29 02:21:43 -08:00
|
|
|
flash[:error] = 'An error occurred. ;_;'
|
2014-11-11 11:20:00 -08:00
|
|
|
end
|
2014-11-03 04:21:41 -08:00
|
|
|
redirect_to edit_user_profile_path
|
2014-11-02 08:57:37 -08:00
|
|
|
end
|
2014-12-08 08:03:06 -08:00
|
|
|
|
2015-01-02 12:34:56 -08:00
|
|
|
def privacy
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2014-12-08 08:03:06 -08:00
|
|
|
def followers
|
|
|
|
@title = 'Followers'
|
2014-12-21 06:32:49 -08:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-12-08 08:10:09 -08:00
|
|
|
@users = @user.followers.reverse_order.paginate(page: params[:page])
|
2014-12-08 10:48:12 -08:00
|
|
|
@type = :friend
|
2014-12-08 08:03:06 -08:00
|
|
|
render 'show_follow'
|
|
|
|
end
|
|
|
|
|
2014-12-08 10:51:34 -08:00
|
|
|
def friends
|
2014-12-08 08:03:06 -08:00
|
|
|
@title = 'Following'
|
2014-12-21 06:32:49 -08:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-12-08 08:10:09 -08:00
|
|
|
@users = @user.friends.reverse_order.paginate(page: params[:page])
|
2014-12-08 10:48:12 -08:00
|
|
|
@type = :friend
|
2014-12-08 08:03:06 -08:00
|
|
|
render 'show_follow'
|
|
|
|
end
|
2014-12-19 13:34:24 -08:00
|
|
|
|
|
|
|
def questions
|
|
|
|
@title = 'Questions'
|
2014-12-21 06:32:49 -08:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-12-19 14:12:19 -08:00
|
|
|
@questions = @user.questions.where(author_is_anonymous: false).reverse_order.paginate(page: params[:page])
|
2014-12-19 13:34:24 -08:00
|
|
|
end
|
2014-11-02 08:57:37 -08:00
|
|
|
end
|