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\Commands\ProjectNamespace\AddProjectNamespaceCommand; |
18
|
|
|
use Gitamin\Models\Invite; |
19
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
20
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
21
|
|
|
use Illuminate\Routing\Controller; |
|
|
|
|
22
|
|
|
use Illuminate\Support\Facades\Redirect; |
23
|
|
|
use Illuminate\Support\Facades\View; |
24
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
25
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
26
|
|
|
|
27
|
|
|
class SignupController extends Controller |
28
|
|
|
{ |
29
|
|
|
use DispatchesJobs; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Handle the signup with invite. |
33
|
|
|
* |
34
|
|
|
* @param string|null $code |
35
|
|
|
* |
36
|
|
|
* @return \Illuminate\View\View |
37
|
|
|
*/ |
38
|
|
|
public function getSignup($code = null) |
39
|
|
|
{ |
40
|
|
|
if ($code === null) { |
|
|
|
|
41
|
|
|
//throw new NotFoundHttpException(); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$invite = Invite::where('code', '=', $code)->first(); |
45
|
|
|
|
46
|
|
|
if (!$invite || $invite->claimed()) { |
|
|
|
|
47
|
|
|
//throw new BadRequestHttpException(); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return View::make('signup') |
51
|
|
|
->withCode($invite ? $invite->code : '') |
52
|
|
|
->withUsername(Binput::old('username')) |
53
|
|
|
->withEmail(Binput::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
|
|
|
|
77
|
|
|
try { |
78
|
|
|
$user = $this->dispatch(new SignupUserCommand( |
79
|
|
|
Binput::get('username'), |
80
|
|
|
Binput::get('password'), |
81
|
|
|
Binput::get('email'), |
82
|
|
|
2 |
83
|
|
|
)); |
84
|
|
|
$namespaceData = [ |
85
|
|
|
'name' => $user->username, |
86
|
|
|
'path' => $user->username, |
87
|
|
|
'owner_id' => $user->id, |
88
|
|
|
'description' => '', |
89
|
|
|
'type' => 'user', |
90
|
|
|
]; |
91
|
|
|
$this->dispatchFromArray(AddProjectNamespaceCommand::class, $namespaceData); |
92
|
|
|
|
93
|
|
|
} catch (ValidationException $e) { |
94
|
|
|
return Redirect::route('auth.signup', ['code' => $code]) |
95
|
|
|
->withInput(Binput::except('password')) |
96
|
|
|
->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('gitamin.signup.failure'))) |
97
|
|
|
->withErrors($e->getMessageBag()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
//$this->dispatch(new ClaimInviteCommand($invite)); |
|
|
|
|
101
|
|
|
|
102
|
|
|
return Redirect::route('auth.login') |
103
|
|
|
->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('gitamin.signup.success'))); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: