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 SessionsHelper |
20
|
|
|
# Logs a user into GreenLight. |
21
|
|
|
def login(user) |
22
|
|
|
migrate_twitter_user(user) |
23
|
|
|
|
24
|
|
|
session[:user_id] = user.id |
25
|
|
|
|
26
|
|
|
# If there are not terms, or the user has accepted them, check for email verification |
27
|
|
|
if !Rails.configuration.terms || user.accepted_terms |
28
|
|
|
check_email_verified(user) |
29
|
|
|
else |
30
|
|
|
redirect_to terms_path |
31
|
|
|
end |
32
|
|
|
end |
33
|
|
|
|
34
|
|
|
# If email verification is disabled, or the user has verified, go to their room |
35
|
|
|
def check_email_verified(user) |
36
|
|
|
# Admin users should be redirected to the admin page |
37
|
|
|
if user.has_role? :super_admin |
38
|
|
|
redirect_to admins_path |
39
|
|
|
elsif user.activated? |
40
|
|
|
# Dont redirect to any of these urls |
41
|
|
|
dont_redirect_to = [root_url, signin_url, signup_url, unauthorized_url, internal_error_url, not_found_url] |
42
|
|
|
url = if cookies[:return_to] && !dont_redirect_to.include?(cookies[:return_to]) |
43
|
|
|
cookies[:return_to] |
44
|
|
|
else |
45
|
|
|
user.main_room |
46
|
|
|
end |
47
|
|
|
|
48
|
|
|
# Delete the cookie if it exists |
49
|
|
|
cookies.delete :return_to if cookies[:return_to] |
50
|
|
|
|
51
|
|
|
redirect_to url |
52
|
|
|
else |
53
|
|
|
redirect_to resend_path |
54
|
|
|
end |
55
|
|
|
end |
56
|
|
|
|
57
|
|
|
# Logs current user out of GreenLight. |
58
|
|
|
def logout |
59
|
|
|
session.delete(:user_id) if current_user |
60
|
|
|
end |
61
|
|
|
|
62
|
|
|
# Retrieves the current user. |
63
|
|
|
def current_user |
64
|
|
|
@current_user ||= User.find_by(id: session[:user_id]) |
65
|
|
|
end |
66
|
|
|
|
67
|
|
|
def generate_checksum(user_domain, redirect_url, secret) |
68
|
|
|
string = user_domain + redirect_url + secret |
69
|
|
|
OpenSSL::Digest.digest('sha1', string).unpack1("H*") |
70
|
|
|
end |
71
|
|
|
|
72
|
|
|
def parse_user_domain(hostname) |
73
|
|
|
return hostname.split('.').first if Rails.configuration.url_host.empty? |
74
|
|
|
Rails.configuration.url_host.split(',').each do |url_host| |
75
|
|
|
return hostname.chomp(url_host).chomp('.') if hostname.include?(url_host) |
76
|
|
|
end |
77
|
|
|
'' |
78
|
|
|
end |
79
|
|
|
|
80
|
|
|
def omniauth_options(env) |
81
|
|
|
if env['omniauth.strategy'].options[:name] == "bn-launcher" |
82
|
|
|
protocol = Rails.env.production? ? "https" : env["rack.url_scheme"] |
83
|
|
|
|
84
|
|
|
customer_redirect_url = protocol + "://" + env["SERVER_NAME"] + ":" + |
85
|
|
|
env["SERVER_PORT"] |
86
|
|
|
user_domain = parse_user_domain(env["SERVER_NAME"]) |
87
|
|
|
env['omniauth.strategy'].options[:customer] = user_domain |
88
|
|
|
env['omniauth.strategy'].options[:customer_redirect_url] = customer_redirect_url |
89
|
|
|
env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url |
90
|
|
|
|
91
|
|
|
# This is only used in the old launcher and should eventually be removed |
92
|
|
|
env['omniauth.strategy'].options[:checksum] = generate_checksum(user_domain, customer_redirect_url, |
93
|
|
|
Rails.configuration.launcher_secret) |
94
|
|
|
elsif env['omniauth.strategy'].options[:name] == "google" |
95
|
|
|
set_hd(env, ENV['GOOGLE_OAUTH2_HD']) |
96
|
|
|
elsif env['omniauth.strategy'].options[:name] == "office365" |
97
|
|
|
set_hd(env, ENV['OFFICE365_HD']) |
98
|
|
|
end |
99
|
|
|
end |
100
|
|
|
|
101
|
|
|
def set_hd(env, hd) |
102
|
|
|
hd_opts = hd.split(',') |
103
|
|
|
env['omniauth.strategy'].options[:hd] = |
104
|
|
|
if hd_opts.empty? |
105
|
|
|
nil |
106
|
|
|
elsif hd_opts.length == 1 |
107
|
|
|
hd_opts[0] |
108
|
|
|
else |
109
|
|
|
hd_opts |
110
|
|
|
end |
111
|
|
|
end |
112
|
|
|
|
113
|
|
|
def migrate_twitter_user(user) |
114
|
|
|
if !session["old_twitter_user_id"].nil? && user.provider != "twitter" |
115
|
|
|
old_user = User.find(session["old_twitter_user_id"]) |
116
|
|
|
|
117
|
|
|
old_user.rooms.each do |room| |
118
|
|
|
room.owner = user |
119
|
|
|
|
120
|
|
|
room.name = "Old " + room.name if room.id == old_user.main_room.id |
121
|
|
|
|
122
|
|
|
room.save! |
123
|
|
|
end |
124
|
|
|
|
125
|
|
|
# Query for the old user again so the migrated rooms don't get deleted |
126
|
|
|
old_user.reload |
127
|
|
|
old_user.destroy! |
128
|
|
|
|
129
|
|
|
session["old_twitter_user_id"] = nil |
130
|
|
|
end |
131
|
|
|
end |
132
|
|
|
end |
133
|
|
|
|