2014-11-02 17:57:37 +01:00
|
|
|
class UserController < ApplicationController
|
2015-01-03 22:48:59 +01:00
|
|
|
before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy)
|
2014-12-29 11:21:43 +01:00
|
|
|
|
2014-11-02 17:57:37 +01:00
|
|
|
def show
|
2014-12-21 15:32:49 +01:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-11-12 20:40:24 +01:00
|
|
|
@answers = @user.answers.reverse_order.paginate(page: params[:page])
|
2014-12-08 15:23:04 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
2014-11-02 17:57:37 +01:00
|
|
|
end
|
|
|
|
|
2015-01-03 21:58:56 +01:00
|
|
|
# region Account settings
|
2014-11-02 17:57:37 +01:00
|
|
|
def edit
|
2014-11-03 13:21:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2014-12-29 11:21:43 +01:00
|
|
|
user_attributes = params.require(:user).permit(:display_name, :profile_picture, :motivation_header, :website,
|
2014-12-29 14:52:06 +01:00
|
|
|
:location, :bio, :crop_x, :crop_y, :crop_w, :crop_h)
|
2014-12-29 14:54:32 +01: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 11:21:43 +01:00
|
|
|
flash[:error] = 'An error occurred. ;_;'
|
2014-11-11 20:20:00 +01:00
|
|
|
end
|
2014-11-03 13:21:41 +01:00
|
|
|
redirect_to edit_user_profile_path
|
2014-11-02 17:57:37 +01:00
|
|
|
end
|
2015-01-03 21:58:56 +01:00
|
|
|
# endregion
|
2014-12-08 17:03:06 +01:00
|
|
|
|
2015-01-03 21:58:56 +01:00
|
|
|
# region Privacy settings
|
|
|
|
def edit_privacy
|
|
|
|
end
|
2015-01-02 21:34:56 +01:00
|
|
|
|
2015-01-03 21:58:56 +01:00
|
|
|
def update_privacy
|
|
|
|
user_attributes = params.require(:user).permit(:privacy_allow_anonymous_questions,
|
|
|
|
:privacy_allow_public_timeline,
|
|
|
|
:privacy_allow_stranger_answers,
|
|
|
|
:privacy_show_in_search)
|
|
|
|
if current_user.update_attributes(user_attributes)
|
|
|
|
flash[:success] = 'Your privacy settings have been updated!'
|
|
|
|
else
|
|
|
|
flash[:error] = 'An error occurred. ;_;'
|
|
|
|
end
|
|
|
|
redirect_to edit_user_privacy_path
|
2015-01-02 21:34:56 +01:00
|
|
|
end
|
2015-01-03 21:58:56 +01:00
|
|
|
# endregion
|
2015-01-02 21:34:56 +01:00
|
|
|
|
2014-12-08 17:03:06 +01:00
|
|
|
def followers
|
|
|
|
@title = 'Followers'
|
2014-12-21 15:32:49 +01:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-12-08 17:10:09 +01:00
|
|
|
@users = @user.followers.reverse_order.paginate(page: params[:page])
|
2014-12-08 19:48:12 +01:00
|
|
|
@type = :friend
|
2014-12-08 17:03:06 +01:00
|
|
|
render 'show_follow'
|
|
|
|
end
|
|
|
|
|
2014-12-08 19:51:34 +01:00
|
|
|
def friends
|
2014-12-08 17:03:06 +01:00
|
|
|
@title = 'Following'
|
2014-12-21 15:32:49 +01:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-12-08 17:10:09 +01:00
|
|
|
@users = @user.friends.reverse_order.paginate(page: params[:page])
|
2014-12-08 19:48:12 +01:00
|
|
|
@type = :friend
|
2014-12-08 17:03:06 +01:00
|
|
|
render 'show_follow'
|
|
|
|
end
|
2014-12-19 22:34:24 +01:00
|
|
|
|
|
|
|
def questions
|
|
|
|
@title = 'Questions'
|
2014-12-21 15:32:49 +01:00
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
2014-12-19 23:12:19 +01:00
|
|
|
@questions = @user.questions.where(author_is_anonymous: false).reverse_order.paginate(page: params[:page])
|
2014-12-19 22:34:24 +01:00
|
|
|
end
|
2014-11-02 17:57:37 +01:00
|
|
|
end
|