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 Illuminate\Support\Facades\Auth; |
15
|
|
|
use Illuminate\Support\Facades\Redirect; |
16
|
|
|
use Illuminate\Support\Facades\Request; |
17
|
|
|
use Illuminate\Support\Facades\Session; |
18
|
|
|
use Illuminate\Support\Facades\View; |
19
|
|
|
use Illuminate\Support\Str; |
20
|
|
|
|
21
|
|
|
class AuthController extends Controller |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Shows the login view. |
25
|
|
|
* |
26
|
|
|
* @return \Illuminate\View\View |
27
|
|
|
*/ |
28
|
|
|
public function showLogin() |
29
|
|
|
{ |
30
|
|
|
return View::make('auth.login') |
31
|
|
|
->withPageTitle(trans('dashboard.login.login')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Logs the user in. |
36
|
|
|
* |
37
|
|
|
* @return \Illuminate\Http\RedirectResponse |
38
|
|
|
*/ |
39
|
|
|
public function postLogin() |
40
|
|
|
{ |
41
|
|
|
$loginData = Request::only(['login', 'password']); |
42
|
|
|
|
43
|
|
|
// Login with username or email. |
44
|
|
|
$loginKey = Str::contains($loginData['login'], '@') ? 'email' : 'username'; |
45
|
|
|
$loginData[$loginKey] = array_pull($loginData, 'login'); |
46
|
|
|
|
47
|
|
|
// Validate login credentials. |
48
|
|
|
if (Auth::validate($loginData)) { |
49
|
|
|
// Log the user in for one request. |
50
|
|
|
Auth::once($loginData); |
51
|
|
|
|
52
|
|
|
// We probably want to add support for "Remember me" here. |
53
|
|
|
Auth::attempt($loginData); |
54
|
|
|
|
55
|
|
|
//return Redirect::intended('/') |
|
|
|
|
56
|
|
|
return Redirect::home() |
57
|
|
|
->withSuccess(trans('gitamin.signin.success')); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return Redirect::route('auth.login') |
61
|
|
|
->withInput(Request::except('password')) |
62
|
|
|
->withError(trans('gitamin.signin.invalid')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Logs the user out, deleting their session etc. |
67
|
|
|
* |
68
|
|
|
* @return \Illuminate\Http\RedirectResponse |
69
|
|
|
*/ |
70
|
|
|
public function logoutAction() |
71
|
|
|
{ |
72
|
|
|
Auth::logout(); |
73
|
|
|
|
74
|
|
|
return Redirect::to('/') |
75
|
|
|
->withSuccess(trans('forms.logout.success')); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.