GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#648)
by
unknown
04:07
created

SessionsHelper.current_user()   B

Complexity

Conditions 6

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 0
loc 13
rs 8.6666
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
66
    if Rails.configuration.loadbalanced_configuration
67
      if @current_user && !@current_user.has_role?(:super_admin) && @user_domain &&
68
         @current_user.provider != @user_domain
69
        @current_user = nil
70
        session.clear
71
      end
72
    end
73
74
    @current_user
75
  end
76
77
  def generate_checksum(user_domain, redirect_url, secret)
78
    string = user_domain + redirect_url + secret
79
    OpenSSL::Digest.digest('sha1', string).unpack1("H*")
80
  end
81
82
  def parse_user_domain(hostname)
83
    return hostname.split('.').first if Rails.configuration.url_host.empty?
84
    Rails.configuration.url_host.split(',').each do |url_host|
85
      return hostname.chomp(url_host).chomp('.') if hostname.include?(url_host)
86
    end
87
    ''
88
  end
89
90
  def omniauth_options(env)
91
    if env['omniauth.strategy'].options[:name] == "bn_launcher"
92
      protocol = Rails.env.production? ? "https" : env["rack.url_scheme"]
93
94
      customer_redirect_url = protocol + "://" + env["SERVER_NAME"] + ":" +
95
                              env["SERVER_PORT"]
96
      user_domain = parse_user_domain(env["SERVER_NAME"])
97
      env['omniauth.strategy'].options[:customer] = user_domain
98
      env['omniauth.strategy'].options[:customer_redirect_url] = customer_redirect_url
99
      env['omniauth.strategy'].options[:default_callback_url] = Rails.configuration.gl_callback_url
100
101
      # This is only used in the old launcher and should eventually be removed
102
      env['omniauth.strategy'].options[:checksum] = generate_checksum(user_domain, customer_redirect_url,
103
        Rails.configuration.launcher_secret)
104
    elsif env['omniauth.strategy'].options[:name] == "google"
105
      set_hd(env, ENV['GOOGLE_OAUTH2_HD'])
106
    elsif env['omniauth.strategy'].options[:name] == "office365"
107
      set_hd(env, ENV['OFFICE365_HD'])
108
    end
109
  end
110
111
  def set_hd(env, hd)
112
    if hd
113
      hd_opts = hd.split(',')
114
      env['omniauth.strategy'].options[:hd] =
115
        if hd_opts.empty?
116
          nil
117
        elsif hd_opts.length == 1
118
          hd_opts[0]
119
        else
120
          hd_opts
121
        end
122
      end
123
  end
124
125
  def migrate_twitter_user(user)
126
    if !session["old_twitter_user_id"].nil? && user.provider != "twitter"
127
      old_user = User.find(session["old_twitter_user_id"])
128
129
      old_user.rooms.each do |room|
130
        room.owner = user
131
132
        room.name = "Old " + room.name if room.id == old_user.main_room.id
133
134
        room.save!
135
      end
136
137
      # Query for the old user again so the migrated rooms don't get deleted
138
      old_user.reload
139
      old_user.destroy!
140
141
      session["old_twitter_user_id"] = nil
142
143
      flash[:success] = I18n.t("registration.deprecated.merge_success")
144
    end
145
  end
146
end
147