|
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 AccountActivationsController < ApplicationController |
|
20
|
|
|
include Emailer |
|
21
|
|
|
include Authenticator |
|
22
|
|
|
|
|
23
|
|
|
before_action :ensure_unauthenticated |
|
24
|
|
|
before_action :find_user_by_token, only: :edit |
|
25
|
|
|
before_action :find_user_by_digest, only: :resend |
|
26
|
|
|
|
|
27
|
|
|
# GET /account_activations |
|
28
|
|
|
def show |
|
29
|
|
|
end |
|
30
|
|
|
|
|
31
|
|
|
# GET /account_activations/edit |
|
32
|
|
|
def edit |
|
33
|
|
|
# If the user exists and is not verified and provided the correct token |
|
34
|
|
|
if @user && [email protected]? |
|
35
|
|
|
# Verify user |
|
36
|
|
|
@user.set_role(initial_user_role(@user.email)) if @user.role.nil? |
|
37
|
|
|
@user.activate |
|
38
|
|
|
|
|
39
|
|
|
# Redirect user to root with account pending flash if account is still pending |
|
40
|
|
|
return redirect_to root_path, |
|
41
|
|
|
flash: { success: I18n.t("registration.approval.signup") } if @user.has_role?(:pending) |
|
42
|
|
|
|
|
43
|
|
|
# Redirect user to sign in path with success flash |
|
44
|
|
|
redirect_to signin_path, flash: { success: I18n.t("verify.activated") + " " + I18n.t("verify.signin") } |
|
45
|
|
|
else |
|
46
|
|
|
redirect_to root_path, flash: { alert: I18n.t("verify.invalid") } |
|
47
|
|
|
end |
|
48
|
|
|
end |
|
49
|
|
|
|
|
50
|
|
|
# POST /account_activations/resend |
|
51
|
|
|
def resend |
|
52
|
|
|
if @user.activated? |
|
53
|
|
|
# User is already verified |
|
54
|
|
|
flash[:alert] = I18n.t("verify.already_verified") |
|
55
|
|
|
else |
|
56
|
|
|
# Resend |
|
57
|
|
|
send_activation_email(@user, @user.create_activation_token) |
|
58
|
|
|
end |
|
59
|
|
|
|
|
60
|
|
|
redirect_to root_path |
|
61
|
|
|
end |
|
62
|
|
|
|
|
63
|
|
|
private |
|
64
|
|
|
|
|
65
|
|
|
def find_user_by_token |
|
66
|
|
|
return redirect_to root_path, flash: { alert: I18n.t("verify.invalid") } unless params[:token].present? |
|
67
|
|
|
|
|
68
|
|
|
@user = User.find_by!(activation_digest: User.hash_token(params[:token]), provider: @user_domain) |
|
69
|
|
|
end |
|
70
|
|
|
|
|
71
|
|
|
def find_user_by_digest |
|
72
|
|
|
@user = User.find_by!(activation_digest: params[:digest], provider: @user_domain) |
|
73
|
|
|
end |
|
74
|
|
|
|
|
75
|
|
|
def ensure_unauthenticated |
|
76
|
|
|
redirect_to current_user.main_room || root_path if current_user |
|
77
|
|
|
end |
|
78
|
|
|
end |
|
79
|
|
|
|