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:26
created

UsersController.send_verification()   A

Complexity

Conditions 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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