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 SessionsController < ApplicationController |
20
|
|
|
include Authenticator |
21
|
|
|
include Registrar |
22
|
|
|
include Emailer |
23
|
|
|
include LdapAuthenticator |
24
|
|
|
include Uploader |
25
|
|
|
|
26
|
|
|
skip_before_action :verify_authenticity_token, only: [:omniauth, :fail] |
27
|
|
|
before_action :check_user_signup_allowed, only: [:new] |
28
|
|
|
before_action :ensure_unauthenticated_except_twitter, only: [:new, :signin] |
29
|
|
|
|
30
|
|
|
# GET /signin |
31
|
|
|
def signin |
32
|
|
|
check_if_twitter_account |
33
|
|
|
|
34
|
|
|
if one_provider |
35
|
|
|
provider_path = if Rails.configuration.omniauth_ldap |
36
|
|
|
ldap_signin_path |
37
|
|
|
else |
38
|
|
|
"#{Rails.configuration.relative_url_root}/auth/#{providers.first}" |
39
|
|
|
end |
40
|
|
|
|
41
|
|
|
return redirect_to provider_path |
42
|
|
|
end |
43
|
|
|
end |
44
|
|
|
|
45
|
|
|
# GET /ldap_signin |
46
|
|
|
def ldap_signin |
47
|
|
|
end |
48
|
|
|
|
49
|
|
|
# GET /signup |
50
|
|
|
def new |
51
|
|
|
# Check if the user needs to be invited |
52
|
|
|
if invite_registration |
53
|
|
|
redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless params[:invite_token] |
54
|
|
|
|
55
|
|
|
session[:invite_token] = params[:invite_token] |
56
|
|
|
end |
57
|
|
|
|
58
|
|
|
check_if_twitter_account(true) |
59
|
|
|
|
60
|
|
|
@user = User.new |
61
|
|
|
end |
62
|
|
|
|
63
|
|
|
# POST /users/login |
64
|
|
|
def create |
65
|
|
|
logger.info "Support: #{session_params[:email]} is attempting to login." |
66
|
|
|
|
67
|
|
|
user = User.include_deleted.find_by(email: session_params[:email], provider: @user_domain) |
68
|
|
|
|
69
|
|
|
# Check user with that email exists |
70
|
|
|
return redirect_to(signin_path, alert: I18n.t("invalid_credentials")) unless user |
71
|
|
|
# Check correct password was entered |
72
|
|
|
return redirect_to(signin_path, alert: I18n.t("invalid_credentials")) unless user.try(:authenticate, |
73
|
|
|
session_params[:password]) |
74
|
|
|
# Check that the user is not deleted |
75
|
|
|
return redirect_to root_path, flash: { alert: I18n.t("registration.banned.fail") } if user.deleted? |
76
|
|
|
|
77
|
|
|
unless user.has_role? :super_admin |
78
|
|
|
# Check that the user is a Greenlight account |
79
|
|
|
return redirect_to(root_path, alert: I18n.t("invalid_login_method")) unless user.greenlight_account? |
80
|
|
|
# Check that the user has verified their account |
81
|
|
|
return redirect_to(account_activation_path(email: user.email)) unless user.activated? |
82
|
|
|
end |
83
|
|
|
|
84
|
|
|
# Convert the user's image to avatar if they have an image and no avatar |
85
|
|
|
convert_image_to_avatar(user) if user.image.present? && !user.avatar.attached? |
86
|
|
|
|
87
|
|
|
login(user) |
88
|
|
|
end |
89
|
|
|
|
90
|
|
|
# GET /users/logout |
91
|
|
|
def destroy |
92
|
|
|
logout |
93
|
|
|
redirect_to root_path |
94
|
|
|
end |
95
|
|
|
|
96
|
|
|
# GET/POST /auth/:provider/callback |
97
|
|
|
def omniauth |
98
|
|
|
@auth = request.env['omniauth.auth'] |
99
|
|
|
|
100
|
|
|
begin |
101
|
|
|
process_signin |
102
|
|
|
rescue => e |
103
|
|
|
logger.error "Error authenticating via omniauth: #{e}" |
104
|
|
|
omniauth_fail |
105
|
|
|
end |
106
|
|
|
end |
107
|
|
|
|
108
|
|
|
# POST /auth/failure |
109
|
|
|
def omniauth_fail |
110
|
|
|
if params[:message].nil? |
111
|
|
|
redirect_to root_path, alert: I18n.t("omniauth_error") |
112
|
|
|
else |
113
|
|
|
redirect_to root_path, alert: I18n.t("omniauth_specific_error", error: params["message"]) |
114
|
|
|
end |
115
|
|
|
end |
116
|
|
|
|
117
|
|
|
# GET /auth/ldap |
118
|
|
|
def ldap |
119
|
|
|
ldap_config = {} |
120
|
|
|
ldap_config[:host] = ENV['LDAP_SERVER'] |
121
|
|
|
ldap_config[:port] = ENV['LDAP_PORT'].to_i != 0 ? ENV['LDAP_PORT'].to_i : 389 |
122
|
|
|
ldap_config[:bind_dn] = ENV['LDAP_BIND_DN'] |
123
|
|
|
ldap_config[:password] = ENV['LDAP_PASSWORD'] |
124
|
|
|
ldap_config[:encryption] = if ENV['LDAP_METHOD'] == 'ssl' |
125
|
|
|
'simple_tls' |
126
|
|
|
elsif ENV['LDAP_METHOD'] == 'tls' |
127
|
|
|
'start_tls' |
128
|
|
|
end |
129
|
|
|
ldap_config[:base] = ENV['LDAP_BASE'] |
130
|
|
|
ldap_config[:uid] = ENV['LDAP_UID'] |
131
|
|
|
|
132
|
|
|
result = send_ldap_request(params[:session], ldap_config) |
133
|
|
|
|
134
|
|
|
return redirect_to(ldap_signin_path, alert: I18n.t("invalid_credentials")) unless result |
135
|
|
|
|
136
|
|
|
@auth = parse_auth(result.first, ENV['LDAP_ROLE_FIELD']) |
137
|
|
|
|
138
|
|
|
begin |
139
|
|
|
process_signin |
140
|
|
|
rescue => e |
141
|
|
|
logger.error "Support: Error authenticating via omniauth: #{e}" |
142
|
|
|
omniauth_fail |
143
|
|
|
end |
144
|
|
|
end |
145
|
|
|
|
146
|
|
|
private |
147
|
|
|
|
148
|
|
|
# Verify that GreenLight is configured to allow user signup. |
149
|
|
|
def check_user_signup_allowed |
150
|
|
|
redirect_to root_path unless Rails.configuration.allow_user_signup |
151
|
|
|
end |
152
|
|
|
|
153
|
|
|
def session_params |
154
|
|
|
params.require(:session).permit(:email, :password) |
155
|
|
|
end |
156
|
|
|
|
157
|
|
|
def one_provider |
158
|
|
|
providers = configured_providers |
159
|
|
|
|
160
|
|
|
(!allow_user_signup? || !allow_greenlight_accounts?) && providers.count == 1 && |
161
|
|
|
!Rails.configuration.loadbalanced_configuration |
162
|
|
|
end |
163
|
|
|
|
164
|
|
|
def check_user_exists |
165
|
|
|
User.exists?(social_uid: @auth['uid'], provider: current_provider) |
166
|
|
|
end |
167
|
|
|
|
168
|
|
|
def check_user_deleted(email) |
169
|
|
|
User.deleted.exists?(email: email, provider: @user_domain) |
170
|
|
|
end |
171
|
|
|
|
172
|
|
|
def check_auth_deleted |
173
|
|
|
User.deleted.exists?(social_uid: @auth['uid'], provider: current_provider) |
174
|
|
|
end |
175
|
|
|
|
176
|
|
|
def current_provider |
177
|
|
|
@auth['provider'] == "bn_launcher" ? @auth['info']['customer'] : @auth['provider'] |
178
|
|
|
end |
179
|
|
|
|
180
|
|
|
# Check if the user already exists, if not then check for invitation |
181
|
|
|
def passes_invite_reqs |
182
|
|
|
return true if @user_exists |
183
|
|
|
|
184
|
|
|
invitation = check_user_invited("", session[:invite_token], @user_domain) |
185
|
|
|
invitation[:present] |
186
|
|
|
end |
187
|
|
|
|
188
|
|
|
def process_signin |
189
|
|
|
@user_exists = check_user_exists |
190
|
|
|
|
191
|
|
|
if !@user_exists && @auth['provider'] == "twitter" |
192
|
|
|
return redirect_to root_path, flash: { alert: I18n.t("registration.deprecated.twitter_signup") } |
193
|
|
|
end |
194
|
|
|
|
195
|
|
|
# Check if user is deleted |
196
|
|
|
return redirect_to root_path, flash: { alert: I18n.t("registration.banned.fail") } if check_auth_deleted |
197
|
|
|
|
198
|
|
|
# If using invitation registration method, make sure user is invited |
199
|
|
View Code Duplication |
return redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless passes_invite_reqs |
|
|
|
|
200
|
|
|
|
201
|
|
|
user = User.from_omniauth(@auth) |
202
|
|
|
|
203
|
|
|
logger.info "Support: Auth user #{user.email} is attempting to login." |
204
|
|
|
|
205
|
|
|
# Add pending role if approval method and is a new user |
206
|
|
|
if approval_registration && !@user_exists |
207
|
|
|
user.add_role :pending |
208
|
|
|
|
209
|
|
|
# Inform admins that a user signed up if emails are turned on |
210
|
|
|
send_approval_user_signup_email(user) |
211
|
|
|
|
212
|
|
|
return redirect_to root_path, flash: { success: I18n.t("registration.approval.signup") } |
213
|
|
|
end |
214
|
|
|
|
215
|
|
|
send_invite_user_signup_email(user) if invite_registration && !@user_exists |
216
|
|
|
|
217
|
|
|
login(user) |
218
|
|
|
|
219
|
|
|
if @auth['provider'] == "twitter" |
220
|
|
|
flash[:alert] = if allow_user_signup? && allow_greenlight_accounts? |
221
|
|
|
I18n.t("registration.deprecated.twitter_signin", link: signup_path(old_twitter_user_id: user.id)) |
222
|
|
|
else |
223
|
|
|
I18n.t("registration.deprecated.twitter_signin", link: signin_path(old_twitter_user_id: user.id)) |
224
|
|
|
end |
225
|
|
|
end |
226
|
|
|
end |
227
|
|
|
end |
228
|
|
|
|