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 (#520)
by Ahmad
03:15
created

UsersController.passes_invite_reqs()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 8
rs 10
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
class UsersController < ApplicationController
20
  include RecordingsHelper
21
  include Pagy::Backend
22
  include Emailer
23
  include Registrar
24
25
  before_action :find_user, only: [:edit, :update, :destroy]
26
  before_action :ensure_unauthenticated, only: [:new, :create]
27
28
  # POST /u
29
  def create
30
    # Verify that GreenLight is configured to allow user signup.
31
    return unless Rails.configuration.allow_user_signup
32
33
    @user = User.new(user_params)
34
    @user.provider = @user_domain
35
36
    # User or recpatcha is not valid
37
    render(:new) && return unless valid_user_or_captcha
38
39
    # Redirect to root if user token is either invalid or expired
40
    return redirect_to root_path, flash: { alert: I18n.t("registration.invite.fail") } unless passes_invite_reqs
41
42
    # Set user to pending if Approval Registration is set
43
    @user.add_role :pending if approval_registration
44
45
    # User has passed all validations required
46
    @user.save
47
48
    # Sign in automatically if email verification is disabled or if user is already verified.
49
    login(@user) && return if !Rails.configuration.enable_email_verification || @user.email_verified
50
51
    send_verification
52
53
    redirect_to root_path
54
  end
55
56
  # GET /signin
57
  def signin
58
  end
59
60
  # GET /signup
61
  def new
62
    return redirect_to root_path unless Rails.configuration.allow_user_signup
63
64
    # Check if the user needs to be invited
65
    if invite_registration
66
      redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless params[:invite_token]
67
68
      session[:invite_token] = params[:invite_token]
69
    end
70
71
    @user = User.new
72
  end
73
74
  # GET /u/:user_uid/edit
75
  def edit
76
    if current_user
77
      redirect_to current_user.main_room if @user != current_user && !current_user.admin_of?(@user)
78
    else
79
      redirect_to root_path
80
    end
81
  end
82
83
  # PATCH /u/:user_uid/edit
84
  def update
85
    if params[:setting] == "password"
86
      # Update the users password.
87
      errors = {}
88
89
      if @user.authenticate(user_params[:password])
90
        # Verify that the new passwords match.
91
        if user_params[:new_password] == user_params[:password_confirmation]
92
          @user.password = user_params[:new_password]
93
        else
94
          # New passwords don't match.
95
          errors[:password_confirmation] = "doesn't match"
96
        end
97
      else
98
        # Original password is incorrect, can't update.
99
        errors[:password] = "is incorrect"
100
      end
101
102
      if errors.empty? && @user.save
103
        # Notify the user that their account has been updated.
104
        flash[:success] = I18n.t("info_update_success")
105
        redirect_to edit_user_path(@user)
106
      else
107
        # Append custom errors.
108
        errors.each { |k, v| @user.errors.add(k, v) }
109
        render :edit, params: { settings: params[:settings] }
110
      end
111
    elsif user_params[:email] != @user.email && @user.update_attributes(user_params)
112
      @user.update_attributes(email_verified: false)
113
      flash[:success] = I18n.t("info_update_success")
114
      redirect_to edit_user_path(@user)
115
    elsif @user.update_attributes(user_params)
116
      update_locale(@user)
117
      flash[:success] = I18n.t("info_update_success")
118
      redirect_to edit_user_path(@user)
119
    else
120
      render :edit, params: { settings: params[:settings] }
121
    end
122
  end
123
124
  # DELETE /u/:user_uid
125
  def destroy
126
    if current_user && current_user == @user
127
      @user.destroy
128
      session.delete(:user_id)
129
    elsif current_user.admin_of?(@user)
130
      begin
131
        @user.destroy
132
      rescue => e
133
        logger.error "Error in user deletion: #{e}"
134
        flash[:alert] = I18n.t(params[:message], default: I18n.t("administrator.flash.delete_fail"))
135
      else
136
        flash[:success] = I18n.t("administrator.flash.delete")
137
      end
138
      redirect_to(admins_path) && return
139
    end
140
    redirect_to root_path
141
  end
142
143
  # GET /u/:user_uid/recordings
144
  def recordings
145
    if current_user && current_user.uid == params[:user_uid]
146
      @search, @order_column, @order_direction, recs =
147
        current_user.all_recordings(params.permit(:search, :column, :direction), true)
148
      @pagy, @recordings = pagy_array(recs)
149
    else
150
      redirect_to root_path
151
    end
152
  end
153
154
  # GET | POST /terms
155
  def terms
156
    redirect_to '/404' unless Rails.configuration.terms
157
158
    if params[:accept] == "true"
159
      current_user.update_attributes(accepted_terms: true)
160
      login(current_user)
161
    end
162
  end
163
164
  private
165
166
  def find_user
167
    @user = User.find_by!(uid: params[:user_uid])
168
  end
169
170
  def ensure_unauthenticated
171
    redirect_to current_user.main_room if current_user
172
  end
173
174
  def user_params
175
    params.require(:user).permit(:name, :email, :image, :password, :password_confirmation,
176
      :new_password, :provider, :accepted_terms, :language)
177
  end
178
179
  def send_verification
180
    # Start email verification and redirect to root.
181
    begin
182
      send_activation_email(@user)
183
    rescue => e
184
      logger.error "Error in email delivery: #{e}"
185
      flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error"))
186
    else
187
      flash[:success] = I18n.t("email_sent", email_type: t("verify.verification"))
188
    end
189
  end
190
191
  # Add validation errors to model if they exist
192
  def valid_user_or_captcha
193
    valid_user = @user.valid?
194
    valid_captcha = Rails.configuration.recaptcha_enabled ? verify_recaptcha(model: @user) : true
195
196
    valid_user && valid_captcha
197
  end
198
199
  # Checks if the user passes the requirements to be invited
200
  def passes_invite_reqs
201
    # check if user needs to be invited and IS invited
202
    invitation = check_user_invited(@user.email, session[:invite_token], @user_domain)
203
204
    @user.email_verified = true if invitation[:verified]
205
206
    invitation[:present]
207
  end
208
end
209