1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers; |
13
|
|
|
|
14
|
|
|
use AltThree\Validator\ValidationException; |
15
|
|
|
use Gitamin\Commands\Invite\ClaimInviteCommand; |
16
|
|
|
use Gitamin\Commands\User\SignupUserCommand; |
17
|
|
|
use Gitamin\Exceptions\UserAlreadyBeenTakenException; |
18
|
|
|
use Gitamin\Models\Invite; |
19
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
20
|
|
|
use Illuminate\Support\Facades\Redirect; |
21
|
|
|
use Illuminate\Support\Facades\Request; |
22
|
|
|
use Illuminate\Support\Facades\View; |
23
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
24
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
25
|
|
|
|
26
|
|
|
class SignupController extends Controller |
27
|
|
|
{ |
28
|
|
|
use DispatchesJobs; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Handle the signup with invite. |
32
|
|
|
* |
33
|
|
|
* @param string|null $code |
34
|
|
|
* |
35
|
|
|
* @return \Illuminate\View\View |
36
|
|
|
*/ |
37
|
|
|
public function getSignup($code = null) |
38
|
|
|
{ |
39
|
|
|
if ($code === null) { |
|
|
|
|
40
|
|
|
//throw new NotFoundHttpException(); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$invite = Invite::where('code', '=', $code)->first(); |
44
|
|
|
|
45
|
|
|
if (! $invite || $invite->claimed()) { |
|
|
|
|
46
|
|
|
//throw new BadRequestHttpException(); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return View::make('signup') |
50
|
|
|
->withCode($invite ? $invite->code : '') |
51
|
|
|
->withPageTitle('signup') |
52
|
|
|
->withUsername(Request::old('username')) |
53
|
|
|
->withEmail(Request::old('emai', $invite ? $invite->email : '')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Handle the unsubscribe. |
58
|
|
|
* |
59
|
|
|
* @param string|null $code |
60
|
|
|
* |
61
|
|
|
* @return \Illuminate\View\View |
62
|
|
|
*/ |
63
|
|
|
public function postSignup($code = null) |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
/* |
|
|
|
|
66
|
|
|
if ($code === null) { |
67
|
|
|
throw new NotFoundHttpException(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$invite = Invite::where('code', '=', $code)->first(); |
71
|
|
|
|
72
|
|
|
if (!$invite || $invite->claimed()) { |
73
|
|
|
throw new BadRequestHttpException(); |
74
|
|
|
} |
75
|
|
|
*/ |
76
|
|
|
$code = 'gitamin'; |
77
|
|
|
try { |
78
|
|
|
$user = $this->dispatch(new SignupUserCommand( |
|
|
|
|
79
|
|
|
Request::get('username'), |
80
|
|
|
Request::get('password'), |
81
|
|
|
Request::get('email'), |
82
|
|
|
2 |
83
|
|
|
)); |
84
|
|
|
} catch (ValidationException $e) { |
85
|
|
|
return Redirect::route('signup.signup', ['code' => $code]) |
86
|
|
|
->withInput(Request::except('password')) |
87
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure'))) |
88
|
|
|
->withErrors($e->getMessageBag()); |
89
|
|
|
} catch (UserAlreadyBeenTakenException $e) { |
90
|
|
|
return Redirect::route('signup.signup', ['code' => $code]) |
91
|
|
|
->withInput(Request::except('password')) |
92
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure'))) |
93
|
|
|
->withErrors($e->getMessage()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
//$this->dispatch(new ClaimInviteCommand($invite)); |
|
|
|
|
97
|
|
|
|
98
|
|
|
return Redirect::route('auth.login') |
99
|
|
|
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('gitamin.signup.success'))); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.