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 Auth as Auth; |
15
|
|
|
use Lang; |
16
|
|
|
use Tinyissue\Form\Login as LoginForm; |
17
|
|
|
use Tinyissue\Http\Requests\FormRequest; |
18
|
|
|
use Tinyissue\Model\Project; |
19
|
|
|
use Tinyissue\Model\User; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* HomeController is the controller class for login, logout, dashboard pages. |
23
|
|
|
* |
24
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class HomeController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Public issues view. |
30
|
|
|
* |
31
|
|
|
* @param User $user |
32
|
|
|
* @param Project $project |
33
|
|
|
* |
34
|
|
|
* @return \Illuminate\View\View |
35
|
|
|
*/ |
36
|
4 |
|
public function getIssues(User $user, Project $project) |
37
|
|
|
{ |
38
|
4 |
|
return view('index.issues', [ |
|
|
|
|
39
|
4 |
|
'activeUsers' => $user->activeUsers(), |
40
|
4 |
|
'projects' => $project->projectsWidthIssues(Project::STATUS_OPEN, Project::PRIVATE_NO)->get(), |
41
|
4 |
|
'sidebar' => 'public', |
42
|
4 |
|
]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* User dashboard. |
47
|
|
|
* |
48
|
|
|
* @return \Illuminate\View\View |
49
|
|
|
*/ |
50
|
10 |
|
public function getDashboard() |
51
|
|
|
{ |
52
|
10 |
|
return view('index.dashboard', [ |
|
|
|
|
53
|
10 |
|
'projects' => $this->auth->user()->projectsWidthActivities(Project::STATUS_OPEN)->get(), |
|
|
|
|
54
|
10 |
|
]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Logout user and redirect to login page. |
59
|
|
|
* |
60
|
|
|
* @return \Illuminate\Http\RedirectResponse |
61
|
|
|
*/ |
62
|
1 |
|
public function getLogout() |
63
|
|
|
{ |
64
|
1 |
|
$this->auth->logout(); |
65
|
|
|
|
66
|
1 |
|
return redirect('/')->with('message', trans('tinyissue.loggedout')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Login page. |
71
|
|
|
* |
72
|
|
|
* @param LoginForm $form |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View |
75
|
|
|
*/ |
76
|
16 |
|
public function getIndex(LoginForm $form) |
77
|
|
|
{ |
78
|
16 |
|
if ($this->auth->user()) { |
79
|
3 |
|
return redirect('dashboard'); |
80
|
|
|
} |
81
|
|
|
|
82
|
13 |
|
return view('user.login', ['form' => $form]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Attempt to log user in or redirect to login page with error. |
87
|
|
|
* |
88
|
|
|
* @param FormRequest\Login $request |
89
|
|
|
* |
90
|
|
|
* @return \Illuminate\Http\RedirectResponse |
91
|
|
|
*/ |
92
|
8 |
|
public function postSignin(FormRequest\Login $request) |
93
|
|
|
{ |
94
|
8 |
|
$credentials = $request->only('email', 'password'); |
95
|
|
|
|
96
|
8 |
|
if ($this->auth->attempt($credentials, $request->has('remember')) |
97
|
8 |
|
&& $this->auth->user()->isActive() |
|
|
|
|
98
|
8 |
|
) { |
99
|
7 |
|
return redirect()->to('/dashboard'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
// Get error message |
103
|
1 |
|
$errorMessage = 'password_incorrect'; |
104
|
1 |
|
if (!$this->auth->guest()) { |
105
|
|
|
if ($this->auth->user()->isInactive()) { |
|
|
|
|
106
|
|
|
$errorMessage = 'user_is_not_active'; |
107
|
|
|
} elseif ($this->auth->user()->isBlocked()) { |
|
|
|
|
108
|
|
|
$errorMessage = 'user_is_blocked'; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// Logged out |
112
|
|
|
$this->auth->logout(); |
113
|
|
|
} |
114
|
|
|
|
115
|
1 |
|
return redirect('/') |
116
|
1 |
|
->withInput($request->only('email')) |
117
|
1 |
|
->with('notice-error', trans('tinyissue.' . $errorMessage)); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|