2014-11-02 17:57:37 +01:00
|
|
|
class UserController < ApplicationController
|
2015-07-29 18:54:33 +02:00
|
|
|
include ThemeHelper
|
|
|
|
|
2015-06-20 20:38:07 +02:00
|
|
|
before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy data)
|
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])
|
2015-02-10 06:53:50 +01:00
|
|
|
|
|
|
|
if user_signed_in?
|
|
|
|
notif = Notification.where(target_type: "Relationship", target_id: @user.active_relationships.where(target_id: current_user.id).pluck(:id), recipient_id: current_user.id, new: true).first
|
|
|
|
unless notif.nil?
|
|
|
|
notif.new = false
|
|
|
|
notif.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
2015-05-08 17:44:16 +02:00
|
|
|
user_attributes = params.require(:user).permit(:display_name, :profile_picture, :profile_header, :motivation_header, :website,
|
2015-05-10 02:57:18 +02:00
|
|
|
:location, :bio, :crop_x, :crop_y, :crop_w, :crop_h, :crop_h_x, :crop_h_y, :crop_h_w, :crop_h_h)
|
2014-12-29 14:54:32 +01:00
|
|
|
if current_user.update_attributes(user_attributes)
|
2015-06-07 19:03:57 +02:00
|
|
|
text = t('flash.user.update.text')
|
|
|
|
text += t('flash.user.update.avatar') if user_attributes[:profile_picture]
|
|
|
|
text += t('flash.user.update.header') if user_attributes[:profile_header]
|
2014-12-29 14:54:32 +01:00
|
|
|
flash[:success] = text
|
|
|
|
else
|
2015-06-07 19:03:57 +02:00
|
|
|
flash[:error] = t('flash.user.update.error')
|
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)
|
2015-06-07 19:03:57 +02:00
|
|
|
flash[:success] = t('flash.user.update_privacy.success')
|
2015-01-03 21:58:56 +01:00
|
|
|
else
|
2015-06-07 19:03:57 +02:00
|
|
|
flash[:error] = t('flash.user.update_privacy.error')
|
2015-01-03 21:58:56 +01:00
|
|
|
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
|
|
|
|
2015-01-12 06:57:43 +01:00
|
|
|
# region Groups
|
|
|
|
def groups
|
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
|
|
|
@groups = if current_user == @user
|
2015-01-12 07:08:06 +01:00
|
|
|
@user.groups
|
2015-01-12 06:57:43 +01:00
|
|
|
else
|
2015-01-12 07:08:06 +01:00
|
|
|
@user.groups.where(private: false)
|
|
|
|
end.all
|
2015-01-12 06:57:43 +01:00
|
|
|
end
|
|
|
|
# endregion
|
|
|
|
|
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
|
2015-06-20 20:38:07 +02:00
|
|
|
|
|
|
|
def data
|
|
|
|
end
|
2015-07-24 19:12:14 +02:00
|
|
|
|
|
|
|
def theme
|
2015-07-29 18:54:33 +02:00
|
|
|
render body: render_theme_with_context, content_type: 'text/css'
|
2015-07-24 19:12:14 +02:00
|
|
|
end
|
2014-11-02 17:57:37 +01:00
|
|
|
end
|