Retrospring/app/controllers/user_controller.rb

101 lines
3.2 KiB
Ruby
Raw Normal View History

2014-11-02 08:57:37 -08:00
class UserController < ApplicationController
2015-07-29 09:54:33 -07:00
include ThemeHelper
2015-06-20 11:38:07 -07:00
before_filter :authenticate_user!, only: %w(edit update edit_privacy update_privacy data)
2014-12-29 02:21:43 -08:00
2014-11-02 08:57:37 -08:00
def show
@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])
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
# 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-05-09 17:57:18 -07: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 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')
end
2014-11-03 04:21:41 -08:00
redirect_to edit_user_profile_path
2014-11-02 08:57:37 -08:00
end
# endregion
2014-12-08 08:03:06 -08:00
# region Privacy settings
def edit_privacy
end
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')
else
2015-06-07 10:03:57 -07:00
flash[:error] = t('flash.user.update_privacy.error')
end
redirect_to edit_user_privacy_path
end
# endregion
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'
@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])
@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'
@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])
@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'
@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
2015-06-20 11:38:07 -07:00
def data
end
2015-07-24 10:12:14 -07:00
def theme
2015-07-29 09:54:33 -07:00
render body: render_theme_with_context, content_type: 'text/css'
2015-07-24 10:12:14 -07:00
end
2014-11-02 08:57:37 -08:00
end