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
Push — v2.4-alpha ( 96ace3...b4736b )
by Ahmad
11:22 queued 05:48
created

Authenticator.check_email_verified()   B

Complexity

Conditions 6

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

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