2014-11-02 08:57:37 -08:00
|
|
|
class UserController < ApplicationController
|
2015-07-29 09:54:33 -07:00
|
|
|
include ThemeHelper
|
|
|
|
|
2020-04-18 16:45:50 -07:00
|
|
|
before_action :authenticate_user!, only: %w(edit update edit_privacy update_privacy edit_theme update_theme preview_theme delete_theme data export begin_export)
|
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!
|
2020-04-20 14:03:57 -07:00
|
|
|
@answers = @user.cursored_answers(last_id: params[:last_id])
|
|
|
|
@answers_last_id = @answers.map(&:id).min
|
|
|
|
@more_data_available = !@user.cursored_answers(last_id: @answers_last_id, size: 1).count.zero?
|
2015-02-09 21:53:50 -08: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 06:23:04 -08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
2014-11-02 08:57:37 -08:00
|
|
|
end
|
|
|
|
|
2015-01-03 12:58:56 -08:00
|
|
|
# region Account settings
|
2014-11-02 08:57:37 -08:00
|
|
|
def edit
|
2014-11-03 04:21:41 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-05-08 08:44:16 -07:00
|
|
|
user_attributes = params.require(:user).permit(:display_name, :profile_picture, :profile_header, :motivation_header, :website,
|
2015-08-25 11:27:06 -07:00
|
|
|
:location, :bio, :crop_x, :crop_y, :crop_w, :crop_h, :crop_h_x, :crop_h_y, :crop_h_w, :crop_h_h, :show_foreign_themes)
|
2014-12-29 05:54:32 -08:00
|
|
|
if current_user.update_attributes(user_attributes)
|
2015-06-07 10:03:57 -07: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 05:54:32 -08:00
|
|
|
flash[:success] = text
|
|
|
|
else
|
2015-06-07 10:03:57 -07:00
|
|
|
flash[:error] = t('flash.user.update.error')
|
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
|
2015-01-03 12:58:56 -08:00
|
|
|
# endregion
|
2014-12-08 08:03:06 -08:00
|
|
|
|
2015-01-03 12:58:56 -08:00
|
|
|
# region Privacy settings
|
|
|
|
def edit_privacy
|
|
|
|
end
|
2015-01-02 12:34:56 -08:00
|
|
|
|
2015-01-03 12:58:56 -08: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 10:03:57 -07:00
|
|
|
flash[:success] = t('flash.user.update_privacy.success')
|
2015-01-03 12:58:56 -08:00
|
|
|
else
|
2015-06-07 10:03:57 -07:00
|
|
|
flash[:error] = t('flash.user.update_privacy.error')
|
2015-01-03 12:58:56 -08:00
|
|
|
end
|
|
|
|
redirect_to edit_user_privacy_path
|
2015-01-02 12:34:56 -08:00
|
|
|
end
|
2015-01-03 12:58:56 -08:00
|
|
|
# endregion
|
2015-01-02 12:34:56 -08:00
|
|
|
|
2015-01-11 21:57:43 -08:00
|
|
|
# region Groups
|
|
|
|
def groups
|
|
|
|
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
|
|
|
|
@groups = if current_user == @user
|
2015-01-11 22:08:06 -08:00
|
|
|
@user.groups
|
2015-01-11 21:57:43 -08:00
|
|
|
else
|
2015-01-11 22:08:06 -08:00
|
|
|
@user.groups.where(private: false)
|
|
|
|
end.all
|
2015-01-11 21:57:43 -08:00
|
|
|
end
|
|
|
|
# endregion
|
|
|
|
|
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!
|
2020-04-20 14:03:57 -07:00
|
|
|
@users = @user.cursored_followers(last_id: params[:last_id])
|
|
|
|
@users_last_id = @users.map(&:id).min
|
|
|
|
@more_data_available = !@user.cursored_followers(last_id: @users_last_id, size: 1).count.zero?
|
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!
|
2020-04-20 14:03:57 -07:00
|
|
|
@users = @user.cursored_friends(last_id: params[:last_id])
|
|
|
|
@users_last_id = @users.map(&:id).min
|
|
|
|
@more_data_available = !@user.cursored_friends(last_id: @users_last_id, size: 1).count.zero?
|
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!
|
2020-04-22 18:31:07 -07:00
|
|
|
@questions = @user.cursored_questions(author_is_anonymous: false, last_id: params[:last_id])
|
2020-04-20 14:03:57 -07:00
|
|
|
@questions_last_id = @questions.map(&:id).min
|
2020-04-22 18:31:07 -07:00
|
|
|
@more_data_available = !@user.cursored_questions(author_is_anonymous: false, last_id: @questions_last_id, size: 1).count.zero?
|
2014-12-19 13:34:24 -08:00
|
|
|
end
|
2015-06-20 11:38:07 -07:00
|
|
|
|
|
|
|
def data
|
|
|
|
end
|
2015-07-24 10:12:14 -07:00
|
|
|
|
2015-08-25 01:26:36 -07:00
|
|
|
def edit_theme
|
|
|
|
end
|
|
|
|
|
2015-08-26 16:56:07 -07:00
|
|
|
def delete_theme
|
|
|
|
current_user.theme.destroy!
|
2020-05-06 13:19:30 -07:00
|
|
|
redirect_to edit_user_theme_path
|
2015-08-26 16:56:07 -07:00
|
|
|
end
|
|
|
|
|
2015-08-25 01:26:36 -07:00
|
|
|
def update_theme
|
|
|
|
update_attributes = params.require(:theme).permit([
|
|
|
|
:primary_color, :primary_text,
|
|
|
|
:danger_color, :danger_text,
|
|
|
|
:success_color, :success_text,
|
|
|
|
:warning_color, :warning_text,
|
|
|
|
:info_color, :info_text,
|
2020-05-04 17:02:16 -07:00
|
|
|
:dark_color, :dark_text,
|
|
|
|
:light_color, :light_text,
|
|
|
|
:raised_background, :raised_accent,
|
|
|
|
:background_color, :body_text,
|
|
|
|
:muted_text, :input_color,
|
|
|
|
:input_text
|
2015-08-25 01:26:36 -07:00
|
|
|
])
|
|
|
|
|
|
|
|
if current_user.theme.nil?
|
|
|
|
current_user.theme = Theme.new update_attributes
|
|
|
|
current_user.theme.user_id = current_user.id
|
|
|
|
|
|
|
|
if current_user.theme.save
|
2015-08-25 11:27:06 -07:00
|
|
|
flash[:success] = 'Theme saved.'
|
2015-08-25 01:26:36 -07:00
|
|
|
else
|
2015-08-25 12:50:17 -07:00
|
|
|
flash[:error] = 'Theme saving failed. ' + current_user.theme.errors.messages.flatten.join(' ')
|
2015-08-25 01:26:36 -07:00
|
|
|
end
|
2015-08-25 11:27:06 -07:00
|
|
|
elsif current_user.theme.update_attributes(update_attributes)
|
|
|
|
flash[:success] = 'Theme saved.'
|
2015-08-25 01:26:36 -07:00
|
|
|
else
|
2015-08-25 12:50:17 -07:00
|
|
|
flash[:error] = 'Theme saving failed. ' + current_user.theme.errors.messages.flatten.join(' ')
|
2015-08-25 01:26:36 -07:00
|
|
|
end
|
|
|
|
redirect_to edit_user_theme_path
|
2015-07-24 10:12:14 -07:00
|
|
|
end
|
2016-01-05 11:54:38 -08:00
|
|
|
|
|
|
|
def export
|
|
|
|
if current_user.export_processing
|
|
|
|
flash[:info] = 'An export is currently in progress for this account.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def begin_export
|
|
|
|
if current_user.can_export?
|
|
|
|
ExportWorker.perform_async(current_user.id)
|
|
|
|
flash[:success] = 'Your account is currently being exported. This will take a little while.'
|
|
|
|
else
|
|
|
|
flash[:error] = 'Nice try, kid.'
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to user_export_path
|
|
|
|
end
|
2014-11-02 08:57:37 -08:00
|
|
|
end
|