|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Tinyissue package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Mohamed Alsharaf <[email protected]> |
|
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 Tinyissue\Http\Controllers; |
|
13
|
|
|
|
|
14
|
|
|
use Tinyissue\Form\Login as LoginForm; |
|
15
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
|
16
|
|
|
use Tinyissue\Model\Project; |
|
17
|
|
|
use Tinyissue\Model\User; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* HomeController is the controller class for login, logout, dashboard pages |
|
21
|
|
|
* |
|
22
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class HomeController extends Controller |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Public issues view |
|
28
|
|
|
* |
|
29
|
|
|
* @param User $user |
|
30
|
|
|
* @param Project $project |
|
31
|
|
|
* @return \Illuminate\View\View |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getIssues(User $user, Project $project) |
|
34
|
|
|
{ |
|
35
|
|
|
return view('index.issues', [ |
|
36
|
|
|
'activeUsers' => $user->activeUsers(), |
|
37
|
|
|
'projects' => $project->projectsWidthIssues(Project::STATUS_OPEN, Project::PRIVATE_NO)->get(), |
|
38
|
|
|
'sidebar' => 'public', |
|
39
|
|
|
]); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* User dashboard |
|
44
|
|
|
* |
|
45
|
|
|
* @return \Illuminate\View\View |
|
46
|
|
|
*/ |
|
47
|
10 |
|
public function getDashboard() |
|
48
|
|
|
{ |
|
49
|
10 |
|
return view('index.dashboard', [ |
|
50
|
10 |
|
'projects' => $this->auth->user()->projectsWidthActivities(Project::STATUS_OPEN)->get(), |
|
|
|
|
|
|
51
|
|
|
]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Logout user and redirect to login page |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getLogout() |
|
60
|
|
|
{ |
|
61
|
1 |
|
$this->auth->logout(); |
|
62
|
|
|
|
|
63
|
1 |
|
return redirect('/')->with('message', trans('tinyissue.loggedout')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Login page |
|
68
|
|
|
* |
|
69
|
|
|
* @param LoginForm $form |
|
70
|
|
|
* |
|
71
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View |
|
72
|
|
|
*/ |
|
73
|
12 |
|
public function getIndex(LoginForm $form) |
|
74
|
|
|
{ |
|
75
|
12 |
|
if ($this->auth->user()) { |
|
76
|
3 |
|
return redirect('dashboard'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
9 |
|
return view('user.login', ['form' => $form]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Attempt to log user in or redirect to login page with error |
|
84
|
|
|
* |
|
85
|
|
|
* @param FormRequest\Login $request |
|
86
|
|
|
* |
|
87
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
88
|
|
|
*/ |
|
89
|
8 |
|
public function postSignin(FormRequest\Login $request) |
|
90
|
|
|
{ |
|
91
|
8 |
|
$credentials = $request->only('email', 'password'); |
|
92
|
|
|
|
|
93
|
8 |
|
if ($this->auth->attempt($credentials, $request->has('remember'))) { |
|
94
|
7 |
|
return redirect()->to('/dashboard'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
return redirect('/') |
|
98
|
1 |
|
->withInput($request->only('email')) |
|
99
|
1 |
|
->with('notice-error', trans('tinyissue.password_incorrect')); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: