1 | <?php |
||||
2 | /** |
||||
3 | * RegisterController.php |
||||
4 | * Copyright (c) 2017 [email protected] |
||||
5 | * |
||||
6 | * This file is part of Firefly III. |
||||
7 | * |
||||
8 | * Firefly III is free software: you can redistribute it and/or modify |
||||
9 | * it under the terms of the GNU General Public License as published by |
||||
10 | * the Free Software Foundation, either version 3 of the License, or |
||||
11 | * (at your option) any later version. |
||||
12 | * |
||||
13 | * Firefly III is distributed in the hope that it will be useful, |
||||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
16 | * GNU General Public License for more details. |
||||
17 | * |
||||
18 | * You should have received a copy of the GNU General Public License |
||||
19 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||||
20 | */ |
||||
21 | /** @noinspection PhpDynamicAsStaticMethodCallInspection */ |
||||
22 | declare(strict_types=1); |
||||
23 | |||||
24 | namespace FireflyIII\Http\Controllers\Auth; |
||||
25 | |||||
26 | use FireflyConfig; |
||||
27 | use FireflyIII\Http\Controllers\Controller; |
||||
28 | use FireflyIII\Support\Http\Controllers\CreateStuff; |
||||
29 | use FireflyIII\Support\Http\Controllers\RequestInformation; |
||||
30 | use FireflyIII\User; |
||||
31 | use Illuminate\Auth\Events\Registered; |
||||
32 | use Illuminate\Foundation\Auth\RegistersUsers; |
||||
33 | use Illuminate\Http\Request; |
||||
34 | |||||
35 | /** |
||||
36 | * Class RegisterController |
||||
37 | * |
||||
38 | * This controller handles the registration of new users as well as their |
||||
39 | * validation and creation. By default this controller uses a trait to |
||||
40 | * provide this functionality without requiring any additional code. |
||||
41 | * |
||||
42 | * @codeCoverageIgnore |
||||
43 | */ |
||||
44 | class RegisterController extends Controller |
||||
45 | { |
||||
46 | use RegistersUsers, RequestInformation, CreateStuff; |
||||
47 | |||||
48 | /** |
||||
49 | * Where to redirect users after registration. |
||||
50 | * |
||||
51 | * @var string |
||||
52 | */ |
||||
53 | protected $redirectTo = '/home'; |
||||
54 | |||||
55 | /** |
||||
56 | * Create a new controller instance. |
||||
57 | */ |
||||
58 | public function __construct() |
||||
59 | { |
||||
60 | parent::__construct(); |
||||
61 | $this->middleware('guest'); |
||||
62 | } |
||||
63 | |||||
64 | /** |
||||
65 | * Handle a registration request for the application. |
||||
66 | * |
||||
67 | * @param Request $request |
||||
68 | * |
||||
69 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View |
||||
70 | */ |
||||
71 | public function register(Request $request) |
||||
72 | { |
||||
73 | // is allowed to? |
||||
74 | $allowRegistration = true; |
||||
75 | $loginProvider = config('firefly.login_provider'); |
||||
76 | $singleUserMode = FireflyConfig::get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
77 | $userCount = User::count(); |
||||
78 | if (true === $singleUserMode && $userCount > 0 && 'eloquent' === $loginProvider) { |
||||
79 | $allowRegistration = false; |
||||
80 | } |
||||
81 | |||||
82 | if ('eloquent' !== $loginProvider) { |
||||
83 | $allowRegistration = false; |
||||
84 | } |
||||
85 | |||||
86 | if (false === $allowRegistration) { |
||||
87 | $message = 'Registration is currently not available.'; |
||||
88 | |||||
89 | return view('error', compact('message')); |
||||
90 | } |
||||
91 | |||||
92 | /** @noinspection PhpUndefinedMethodInspection */ |
||||
93 | $this->validator($request->all())->validate(); |
||||
94 | |||||
95 | event(new Registered($user = $this->createUser($request->all()))); |
||||
96 | |||||
97 | $this->guard()->login($user); |
||||
98 | |||||
99 | session()->flash('success', (string)trans('firefly.registered')); |
||||
100 | |||||
101 | $this->registered($request, $user); |
||||
102 | |||||
103 | return redirect($this->redirectPath()); |
||||
104 | } |
||||
105 | |||||
106 | /** |
||||
107 | * Show the application registration form. |
||||
108 | * |
||||
109 | * @param Request $request |
||||
110 | * |
||||
111 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||||
112 | */ |
||||
113 | public function showRegistrationForm(Request $request) |
||||
114 | { |
||||
115 | $allowRegistration = true; |
||||
116 | $loginProvider = config('firefly.login_provider'); |
||||
117 | $isDemoSite = FireflyConfig::get('is_demo_site', config('firefly.configuration.is_demo_site'))->data; |
||||
0 ignored issues
–
show
The method
FireflyIII\Support\Facades\FireflyConfig::get() is not static, but was called statically.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
118 | $singleUserMode = FireflyConfig::get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; |
||||
119 | $userCount = User::count(); |
||||
120 | $pageTitle = (string)trans('firefly.register_page_title'); |
||||
121 | |||||
122 | if (true === $isDemoSite) { |
||||
123 | $allowRegistration = false; |
||||
124 | } |
||||
125 | |||||
126 | if (true === $singleUserMode && $userCount > 0 && 'eloquent' === $loginProvider) { |
||||
127 | $allowRegistration = false; |
||||
128 | } |
||||
129 | |||||
130 | if ('eloquent' !== $loginProvider) { |
||||
131 | $allowRegistration = false; |
||||
132 | } |
||||
133 | |||||
134 | if (false === $allowRegistration) { |
||||
135 | $message = 'Registration is currently not available.'; |
||||
136 | |||||
137 | return view('error', compact('message')); |
||||
138 | } |
||||
139 | |||||
140 | $email = $request->old('email'); |
||||
141 | |||||
142 | return view('auth.register', compact('isDemoSite', 'email', 'pageTitle')); |
||||
143 | } |
||||
144 | |||||
145 | } |
||||
146 |