1
|
|
|
# frozen_string_literal: true |
2
|
|
|
|
3
|
|
|
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. |
4
|
|
|
# |
5
|
|
|
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below). |
6
|
|
|
# |
7
|
|
|
# This program is free software; you can redistribute it and/or modify it under the |
8
|
|
|
# terms of the GNU Lesser General Public License as published by the Free Software |
9
|
|
|
# Foundation; either version 3.0 of the License, or (at your option) any later |
10
|
|
|
# version. |
11
|
|
|
# |
12
|
|
|
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY |
13
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
14
|
|
|
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
15
|
|
|
# |
16
|
|
|
# You should have received a copy of the GNU Lesser General Public License along |
17
|
|
|
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>. |
18
|
|
|
|
19
|
|
|
class UsersController < ApplicationController |
20
|
|
|
include Pagy::Backend |
21
|
|
|
include Authenticator |
22
|
|
|
include Emailer |
23
|
|
|
include Registrar |
24
|
|
|
include Recorder |
25
|
|
|
include Rolify |
26
|
|
|
|
27
|
|
|
before_action :find_user, only: [:edit, :change_password, :delete_account, :update, :destroy] |
28
|
|
|
before_action :ensure_unauthenticated, only: [:new, :create, :signin] |
29
|
|
|
before_action :check_admin_of, only: [:edit, :change_password, :delete_account] |
30
|
|
|
|
31
|
|
|
# POST /u |
32
|
|
|
def create |
33
|
|
|
# Verify that GreenLight is configured to allow user signup. |
34
|
|
|
return unless Rails.configuration.allow_user_signup |
35
|
|
|
|
36
|
|
|
@user = User.new(user_params) |
37
|
|
|
@user.provider = @user_domain |
38
|
|
|
|
39
|
|
|
# User or recpatcha is not valid |
40
|
|
|
render(:new) && return unless valid_user_or_captcha |
41
|
|
|
|
42
|
|
|
# Redirect to root if user token is either invalid or expired |
43
|
|
View Code Duplication |
return redirect_to root_path, flash: { alert: I18n.t("registration.invite.fail") } unless passes_invite_reqs |
|
|
|
|
44
|
|
|
|
45
|
|
|
# User has passed all validations required |
46
|
|
|
@user.save |
47
|
|
|
|
48
|
|
|
logger.info "Support: #{@user.email} user has been created." |
49
|
|
|
|
50
|
|
|
# Set user to pending and redirect if Approval Registration is set |
51
|
|
|
if approval_registration |
52
|
|
|
@user.add_role :pending |
53
|
|
|
|
54
|
|
|
return redirect_to root_path, |
55
|
|
|
flash: { success: I18n.t("registration.approval.signup") } unless Rails.configuration.enable_email_verification |
56
|
|
|
end |
57
|
|
|
|
58
|
|
|
send_registration_email |
59
|
|
|
|
60
|
|
|
# Sign in automatically if email verification is disabled or if user is already verified. |
61
|
|
|
login(@user) && return if !Rails.configuration.enable_email_verification || @user.email_verified |
62
|
|
|
|
63
|
|
|
send_activation_email(@user) |
64
|
|
|
|
65
|
|
|
redirect_to root_path |
66
|
|
|
end |
67
|
|
|
|
68
|
|
|
# GET /signin |
69
|
|
|
def signin |
70
|
|
|
check_if_twitter_account |
71
|
|
|
|
72
|
|
|
providers = configured_providers |
73
|
|
|
if (!allow_user_signup? || !allow_greenlight_accounts?) && providers.count == 1 && |
74
|
|
|
!Rails.configuration.loadbalanced_configuration |
75
|
|
|
provider_path = if Rails.configuration.omniauth_ldap |
76
|
|
|
ldap_signin_path |
77
|
|
|
else |
78
|
|
|
"#{Rails.configuration.relative_url_root}/auth/#{providers.first}" |
79
|
|
|
end |
80
|
|
|
|
81
|
|
|
return redirect_to provider_path |
82
|
|
|
end |
83
|
|
|
end |
84
|
|
|
|
85
|
|
|
# GET /ldap_signin |
86
|
|
|
def ldap_signin |
87
|
|
|
end |
88
|
|
|
|
89
|
|
|
# GET /signup |
90
|
|
|
def new |
91
|
|
|
return redirect_to root_path unless Rails.configuration.allow_user_signup |
92
|
|
|
|
93
|
|
|
# Check if the user needs to be invited |
94
|
|
|
if invite_registration |
95
|
|
|
redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless params[:invite_token] |
96
|
|
|
|
97
|
|
|
session[:invite_token] = params[:invite_token] |
98
|
|
|
end |
99
|
|
|
|
100
|
|
|
check_if_twitter_account(true) |
101
|
|
|
|
102
|
|
|
@user = User.new |
103
|
|
|
end |
104
|
|
|
|
105
|
|
|
# GET /u/:user_uid/edit |
106
|
|
|
def edit |
107
|
|
|
redirect_to root_path unless current_user |
108
|
|
|
end |
109
|
|
|
|
110
|
|
|
# GET /u/:user_uid/change_password |
111
|
|
|
def change_password |
112
|
|
|
redirect_to edit_user_path unless current_user.greenlight_account? |
113
|
|
|
end |
114
|
|
|
|
115
|
|
|
# GET /u/:user_uid/delete_account |
116
|
|
|
def delete_account |
117
|
|
|
end |
118
|
|
|
|
119
|
|
|
# PATCH /u/:user_uid/edit |
120
|
|
|
def update |
121
|
|
|
profile = params[:setting] == "password" ? change_password_path(@user) : edit_user_path(@user) |
122
|
|
|
redirect_path = current_user.admin_of?(@user) ? admins_path : profile |
123
|
|
|
|
124
|
|
|
if params[:setting] == "password" |
125
|
|
|
# Update the users password. |
126
|
|
|
|
127
|
|
|
if @user.authenticate(user_params[:password]) |
128
|
|
|
# Verify that the new passwords match. |
129
|
|
|
if user_params[:new_password] == user_params[:password_confirmation] |
130
|
|
|
@user.password = user_params[:new_password] |
131
|
|
|
else |
132
|
|
|
# New passwords don't match. |
133
|
|
|
@user.errors.add(:password_confirmation, "doesn't match") |
134
|
|
|
end |
135
|
|
|
else |
136
|
|
|
# Original password is incorrect, can't update. |
137
|
|
|
@user.errors.add(:password, "is incorrect") |
138
|
|
|
end |
139
|
|
|
|
140
|
|
|
# Notify the user that their account has been updated. |
141
|
|
|
return redirect_to redirect_path, |
142
|
|
|
flash: { success: I18n.t("info_update_success") } if @user.errors.empty? && @user.save |
143
|
|
|
|
144
|
|
|
render :change_password |
145
|
|
|
else |
146
|
|
|
if @user.update_attributes(user_params) |
147
|
|
|
@user.update_attributes(email_verified: false) if user_params[:email] != @user.email |
148
|
|
|
|
149
|
|
|
user_locale(@user) |
150
|
|
|
|
151
|
|
|
if update_roles(params[:user][:role_ids]) |
152
|
|
|
return redirect_to redirect_path, flash: { success: I18n.t("info_update_success") } |
153
|
|
|
else |
154
|
|
|
flash[:alert] = I18n.t("administrator.roles.invalid_assignment") |
155
|
|
|
end |
156
|
|
|
end |
157
|
|
|
|
158
|
|
|
render :edit |
159
|
|
|
end |
160
|
|
|
end |
161
|
|
|
|
162
|
|
|
# DELETE /u/:user_uid |
163
|
|
|
def destroy |
164
|
|
|
logger.info "Support: #{current_user.email} is deleting #{@user.email}." |
165
|
|
|
|
166
|
|
|
self_delete = current_user == @user |
167
|
|
|
begin |
168
|
|
|
if current_user && (self_delete || current_user.admin_of?(@user)) |
169
|
|
|
@user.destroy |
170
|
|
|
session.delete(:user_id) if self_delete |
171
|
|
|
|
172
|
|
|
return redirect_to admins_path, flash: { success: I18n.t("administrator.flash.delete") } unless self_delete |
173
|
|
|
end |
174
|
|
|
rescue => e |
175
|
|
|
logger.error "Support: Error in user deletion: #{e}" |
176
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("administrator.flash.delete_fail")) |
177
|
|
|
end |
178
|
|
|
|
179
|
|
|
redirect_to root_path |
180
|
|
|
end |
181
|
|
|
|
182
|
|
|
# GET /u/:user_uid/recordings |
183
|
|
|
def recordings |
184
|
|
|
if current_user && current_user.uid == params[:user_uid] |
185
|
|
|
@search, @order_column, @order_direction, recs = |
186
|
|
|
all_recordings(current_user.rooms.pluck(:bbb_id), params.permit(:search, :column, :direction), true) |
187
|
|
|
@pagy, @recordings = pagy_array(recs) |
188
|
|
|
else |
189
|
|
|
redirect_to root_path |
190
|
|
|
end |
191
|
|
|
end |
192
|
|
|
|
193
|
|
|
# GET | POST /terms |
194
|
|
|
def terms |
195
|
|
|
redirect_to '/404' unless Rails.configuration.terms |
196
|
|
|
|
197
|
|
|
if params[:accept] == "true" |
198
|
|
|
current_user.update_attributes(accepted_terms: true) |
199
|
|
|
login(current_user) |
200
|
|
|
end |
201
|
|
|
end |
202
|
|
|
|
203
|
|
|
private |
204
|
|
|
|
205
|
|
|
def find_user |
206
|
|
|
@user = User.where(uid: params[:user_uid]).includes(:roles).first |
207
|
|
|
end |
208
|
|
|
|
209
|
|
|
def ensure_unauthenticated |
210
|
|
|
redirect_to current_user.main_room if current_user && params[:old_twitter_user_id].nil? |
211
|
|
|
end |
212
|
|
|
|
213
|
|
|
def user_params |
214
|
|
|
params.require(:user).permit(:name, :email, :image, :password, :password_confirmation, |
215
|
|
|
:new_password, :provider, :accepted_terms, :language) |
216
|
|
|
end |
217
|
|
|
|
218
|
|
|
def send_registration_email |
219
|
|
|
if invite_registration |
220
|
|
|
send_invite_user_signup_email(@user) |
221
|
|
|
elsif approval_registration |
222
|
|
|
send_approval_user_signup_email(@user) |
223
|
|
|
end |
224
|
|
|
end |
225
|
|
|
|
226
|
|
|
# Checks that the user is allowed to edit this user |
227
|
|
|
def check_admin_of |
228
|
|
|
redirect_to current_user.main_room if current_user && @user != current_user && !current_user.admin_of?(@user) |
229
|
|
|
end |
230
|
|
|
end |
231
|
|
|
|