Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#auth_unbindObject


46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/users_controller.rb', line 46

def auth_unbind
  provider = params[:provider]
  if current_user.authorizations.count <= 1
    redirect_to edit_user_registration_path, flash: { error: t('users.unbind_warning') }
    return
  end

  current_user.authorizations.where(provider: provider).delete_all
  redirect_to edit_user_registration_path, flash: { warring: t('users.unbind_success', provider: provider.titleize) }
end

#blockObject


74
75
76
77
# File 'app/controllers/users_controller.rb', line 74

def block
  current_user.block_user(@user.id)
  render json: { code: 0 }
end

#blockedObject


84
85
86
87
88
89
90
# File 'app/controllers/users_controller.rb', line 84

def blocked
  if current_user.id != @user.id
    render_404
  end

  @blocked_users = User.where(id: current_user.blocked_user_ids).paginate(page: params[:page], per_page: 20)
end

#calendarObject


113
114
115
# File 'app/controllers/users_controller.rb', line 113

def calendar
  render json: @user.calendar_data
end

#cityObject


62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/users_controller.rb', line 62

def city
  @location = Location.location_find_by_name(params[:id])
  if @location.blank?
    render_404
    return
  end

  @users = User.where(location_id: @location.id).fields_for_list.order(replies_count: :desc).paginate(page: params[:page], per_page: 60)

  render_404 if @users.count == 0
end

#favoritesObject


32
33
34
35
36
37
38
39
# File 'app/controllers/users_controller.rb', line 32

def favorites
  @topic_ids = @user.favorite_topic_ids.reverse.paginate(page: params[:page], per_page: 40)
  @topics = Topic.where(id: @topic_ids).fields_for_list
  @topics = @topics.to_a.sort do |a, b|
    @topic_ids.index(a.id) <=> @topic_ids.index(b.id)
  end
  set_seo_meta("#{@user.} 的收藏")
end

#followObject


92
93
94
95
# File 'app/controllers/users_controller.rb', line 92

def follow
  current_user.follow_user(@user)
  render json: { code: 0, data: { followers_count: @user.followers_count } }
end

#followersObject


102
103
104
105
# File 'app/controllers/users_controller.rb', line 102

def followers
  @users = @user.followers.fields_for_list.paginate(page: params[:page], per_page: 60)
  set_seo_meta("#{@user.} 的关注者")
end

#followingObject


107
108
109
110
111
# File 'app/controllers/users_controller.rb', line 107

def following
  @users = @user.following.fields_for_list.paginate(page: params[:page], per_page: 60)
  set_seo_meta("#{@user.} 正在关注")
  render 'followers'
end

#indexObject


8
9
10
11
12
# File 'app/controllers/users_controller.rb', line 8

def index
  @total_user_count = User.count
  @active_users = User.fields_for_list.hot.limit(100)
  set_seo_meta('活跃会员')
end

#notesObject


41
42
43
44
# File 'app/controllers/users_controller.rb', line 41

def notes
  @notes = @user.notes.published.recent.paginate(page: params[:page], per_page: 40)
  set_seo_meta("#{@user.} 的记事本")
end

#repliesObject


27
28
29
30
# File 'app/controllers/users_controller.rb', line 27

def replies
  @replies = @user.replies.fields_for_list.recent.paginate(page: params[:page], per_page: 20)
  set_seo_meta("#{@user.} 的帖子")
end

#showObject


14
15
16
17
18
19
20
# File 'app/controllers/users_controller.rb', line 14

def show
  # 排除掉几个非技术的节点
  without_node_ids = [21, 22, 23, 31, 49, 51, 57, 25]
  @topics = @user.topics.fields_for_list.without_node_ids(without_node_ids).high_likes.limit(20)
  @replies = @user.replies.fields_for_list.recent.includes(:topic).limit(10)
  set_seo_meta("#{@user.}")
end

#topicsObject


22
23
24
25
# File 'app/controllers/users_controller.rb', line 22

def topics
  @topics = @user.topics.fields_for_list.recent.paginate(page: params[:page], per_page: 40)
  set_seo_meta("#{@user.} 的帖子")
end

#unblockObject


79
80
81
82
# File 'app/controllers/users_controller.rb', line 79

def unblock
  current_user.unblock_user(@user.id)
  render json: { code: 0 }
end

#unfollowObject


97
98
99
100
# File 'app/controllers/users_controller.rb', line 97

def unfollow
  current_user.unfollow_user(@user)
  render json: { code: 0, data: { followers_count: @user.followers_count } }
end

#update_private_tokenObject


57
58
59
60
# File 'app/controllers/users_controller.rb', line 57

def update_private_token
  current_user.update_private_token
  render plain: current_user.private_token
end