|
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 Registrar |
|
21
|
|
|
|
|
22
|
|
|
skip_before_action :verify_authenticity_token, only: [:omniauth, :fail] |
|
23
|
|
|
|
|
24
|
|
|
# GET /users/logout |
|
25
|
|
|
def destroy |
|
26
|
|
|
logout |
|
27
|
|
|
redirect_to root_path |
|
28
|
|
|
end |
|
29
|
|
|
|
|
30
|
|
|
# POST /users/login |
|
31
|
|
|
def create |
|
32
|
|
|
admin = User.find_by(email: session_params[:email]) |
|
33
|
|
|
if admin&.has_role? :super_admin |
|
34
|
|
|
user = admin |
|
35
|
|
|
else |
|
36
|
|
|
user = User.find_by(email: session_params[:email], provider: @user_domain) |
|
37
|
|
|
redirect_to(root_path, alert: I18n.t("invalid_user")) && return unless user |
|
38
|
|
|
redirect_to(root_path, alert: I18n.t("invalid_login_method")) && return unless user.greenlight_account? |
|
39
|
|
|
redirect_to(account_activation_path(email: user.email)) && return unless user.activated? |
|
40
|
|
|
end |
|
41
|
|
|
redirect_to(root_path, alert: I18n.t("invalid_credentials")) && return unless user.try(:authenticate, |
|
42
|
|
|
session_params[:password]) |
|
43
|
|
|
|
|
44
|
|
|
login(user) |
|
45
|
|
|
end |
|
46
|
|
|
|
|
47
|
|
|
# GET/POST /auth/:provider/callback |
|
48
|
|
|
def omniauth |
|
49
|
|
|
# If using invitation registration method, make sure user is invited |
|
50
|
|
|
begin |
|
51
|
|
|
@auth = request.env['omniauth.auth'] |
|
52
|
|
|
if passes_invite_reqs |
|
53
|
|
|
user = User.from_omniauth(@auth) |
|
54
|
|
|
login(user) |
|
55
|
|
|
else |
|
56
|
|
|
flash[:alert] = I18n.t("registration.invite.no_invite") |
|
57
|
|
|
redirect_to root_path |
|
58
|
|
|
end |
|
59
|
|
|
rescue => e |
|
60
|
|
|
logger.error "Error authenticating via omniauth: #{e}" |
|
61
|
|
|
omniauth_fail |
|
62
|
|
|
end |
|
63
|
|
|
end |
|
64
|
|
|
|
|
65
|
|
|
# POST /auth/failure |
|
66
|
|
|
def omniauth_fail |
|
67
|
|
|
redirect_to root_path, alert: I18n.t(params[:message], default: I18n.t("omniauth_error")) |
|
68
|
|
|
end |
|
69
|
|
|
|
|
70
|
|
|
private |
|
71
|
|
|
|
|
72
|
|
|
def session_params |
|
73
|
|
|
params.require(:session).permit(:email, :password) |
|
74
|
|
|
end |
|
75
|
|
|
|
|
76
|
|
|
# Check if the user already exists, if not then check for invitation |
|
77
|
|
|
def passes_invite_reqs |
|
78
|
|
|
provider = @auth['provider'] == "bn_launcher" ? @auth['info']['customer'] : @auth['provider'] |
|
79
|
|
|
user_exists = User.exists?(social_uid: @auth['uid'], provider: provider) |
|
80
|
|
|
|
|
81
|
|
|
return true if user_exists |
|
82
|
|
|
|
|
83
|
|
|
invitation = check_user_invited("", session[:invite_token], @user_domain) |
|
84
|
|
|
invitation[:present] |
|
85
|
|
|
end |
|
86
|
|
|
end |
|
87
|
|
|
|