Completed
Branch master (ce2c9c)
by Jesus
04:32
created

Registrar.check_user_invited()   A

Complexity

Conditions 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
dl 0
loc 14
rs 9.7
c 1
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 Registrar
20
  extend ActiveSupport::Concern
21
22
  def registration_method
23
    Setting.find_or_create_by!(provider: user_settings_provider).get_value("Registration Method")
24
  end
25
26
  def open_registration
27
     registration_method == Rails.configuration.registration_methods[:open]
28
  end
29
30
  def approval_registration
31
     registration_method == Rails.configuration.registration_methods[:approval]
32
  end
33
34
  def invite_registration
35
     registration_method == Rails.configuration.registration_methods[:invite]
36
  end
37
38
  # Returns a hash containing whether the user has been invited and if they
39
  # signed up with the same email that they were invited with
40
  def check_user_invited(email, token, domain)
41
    return { present: true, verified: false } unless invite_registration
42
    return { present: false, verified: false } if token.nil?
43
44
    invite = Invitation.valid.find_by(invite_token: token, provider: domain)
45
    if invite.present?
46
      # Check if they used the same email to sign up
47
      same_email = email.casecmp(invite.email).zero?
48
      invite.destroy
49
      { present: true, verified: same_email }
50
    else
51
      { present: false, verified: false }
52
    end
53
  end
54
end
55