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
08:52 queued 04:57
created

UsersController.find_user()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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