|
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
|
|
|
module Authenticator |
|
20
|
|
|
extend ActiveSupport::Concern |
|
21
|
|
|
|
|
22
|
|
|
# Logs a user into GreenLight. |
|
23
|
|
|
def login(user) |
|
24
|
|
|
migrate_twitter_user(user) |
|
25
|
|
|
|
|
26
|
|
|
session[:user_id] = user.id |
|
27
|
|
|
|
|
28
|
|
|
logger.info("Support: #{user.email} has successfully logged in.") |
|
29
|
|
|
|
|
30
|
|
|
# If there are not terms, or the user has accepted them, check for email verification |
|
31
|
|
|
if !Rails.configuration.terms || user.accepted_terms |
|
32
|
|
|
check_email_verified(user) |
|
33
|
|
|
else |
|
34
|
|
|
redirect_to terms_path |
|
35
|
|
|
end |
|
36
|
|
|
end |
|
37
|
|
|
|
|
38
|
|
|
# If email verification is disabled, or the user has verified, go to their room |
|
39
|
|
|
def check_email_verified(user) |
|
40
|
|
|
# Admin users should be redirected to the admin page |
|
41
|
|
|
if user.has_role? :super_admin |
|
42
|
|
|
redirect_to admins_path |
|
43
|
|
|
elsif user.activated? |
|
44
|
|
|
# Dont redirect to any of these urls |
|
45
|
|
|
dont_redirect_to = [root_url, signin_url, signup_url, unauthorized_url, internal_error_url, not_found_url] |
|
46
|
|
|
url = if cookies[:return_to] && !dont_redirect_to.include?(cookies[:return_to]) |
|
47
|
|
|
cookies[:return_to] |
|
48
|
|
|
else |
|
49
|
|
|
user.main_room |
|
50
|
|
|
end |
|
51
|
|
|
|
|
52
|
|
|
# Delete the cookie if it exists |
|
53
|
|
|
cookies.delete :return_to if cookies[:return_to] |
|
54
|
|
|
|
|
55
|
|
|
redirect_to url |
|
56
|
|
|
else |
|
57
|
|
|
redirect_to resend_path |
|
58
|
|
|
end |
|
59
|
|
|
end |
|
60
|
|
|
|
|
61
|
|
|
def ensure_unauthenticated_except_twitter |
|
62
|
|
|
redirect_to current_user.main_room if current_user && params[:old_twitter_user_id].nil? |
|
63
|
|
|
end |
|
64
|
|
|
|
|
65
|
|
|
# Logs current user out of GreenLight. |
|
66
|
|
|
def logout |
|
67
|
|
|
session.delete(:user_id) if current_user |
|
68
|
|
|
end |
|
69
|
|
|
|
|
70
|
|
|
private |
|
71
|
|
|
|
|
72
|
|
|
# Migrates all of the twitter users rooms to the new account |
|
73
|
|
|
def migrate_twitter_user(user) |
|
74
|
|
|
if !session["old_twitter_user_id"].nil? && user.provider != "twitter" |
|
75
|
|
|
old_user = User.find(session["old_twitter_user_id"]) |
|
76
|
|
|
|
|
77
|
|
|
old_user.rooms.each do |room| |
|
78
|
|
|
room.owner = user |
|
79
|
|
|
|
|
80
|
|
|
room.name = "Old " + room.name if room.id == old_user.main_room.id |
|
81
|
|
|
|
|
82
|
|
|
room.save! |
|
83
|
|
|
end |
|
84
|
|
|
|
|
85
|
|
|
# Query for the old user again so the migrated rooms don't get deleted |
|
86
|
|
|
old_user.reload |
|
87
|
|
|
old_user.destroy! |
|
88
|
|
|
|
|
89
|
|
|
session["old_twitter_user_id"] = nil |
|
90
|
|
|
|
|
91
|
|
|
flash[:success] = I18n.t("registration.deprecated.merge_success") |
|
92
|
|
|
end |
|
93
|
|
|
end |
|
94
|
|
|
end |
|
95
|
|
|
|