|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mascame\Artificer\Http\Controllers\Auth; |
|
4
|
|
|
|
|
5
|
|
|
use App\User; |
|
6
|
|
|
use Mascame\Artificer\Http\Controllers\BaseController; |
|
7
|
|
|
use Validator; |
|
8
|
|
|
use Illuminate\Foundation\Auth\ThrottlesLogins; |
|
9
|
|
|
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers; |
|
10
|
|
|
|
|
11
|
|
|
class AuthController extends BaseController |
|
12
|
|
|
{ |
|
13
|
|
|
/* |
|
14
|
|
|
|-------------------------------------------------------------------------- |
|
15
|
|
|
| Registration & Login Controller |
|
16
|
|
|
|-------------------------------------------------------------------------- |
|
17
|
|
|
| |
|
18
|
|
|
| This controller handles the registration of new users, as well as the |
|
19
|
|
|
| authentication of existing users. By default, this controller uses |
|
20
|
|
|
| a simple trait to add these behaviors. Why don't you explore it? |
|
21
|
|
|
| |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
use AuthenticatesAndRegistersUsers, ThrottlesLogins; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Where to redirect users after login / registration. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $redirectTo; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Create a new authentication controller instance. |
|
35
|
|
|
* |
|
36
|
|
|
* @return void |
|
|
|
|
|
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->redirectTo = \URL::route('admin.home'); |
|
41
|
|
|
$this->guard = 'admin'; |
|
42
|
|
|
|
|
43
|
|
|
$this->middleware($this->guestMiddleware(), ['except' => 'logout']); |
|
44
|
|
|
|
|
45
|
|
|
parent::__construct(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Get a validator for an incoming registration request. |
|
50
|
|
|
* |
|
51
|
|
|
* @param array $data |
|
52
|
|
|
* @return \Illuminate\Contracts\Validation\Validator |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function validator(array $data) |
|
55
|
|
|
{ |
|
56
|
|
|
return Validator::make($data, [ |
|
57
|
|
|
'name' => 'required|max:255', |
|
58
|
|
|
'email' => 'required|email|max:255|unique:artificer_users', |
|
59
|
|
|
'password' => 'required|min:6|confirmed', |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function validate(\Illuminate\Http\Request $request, array $data) |
|
64
|
|
|
{ |
|
65
|
|
|
// Allow email or username |
|
66
|
|
|
$field = filter_var($request->input('username'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username'; |
|
67
|
|
|
$this->username = $field; |
|
68
|
|
|
$request->merge([$field => $request->input('username')]); |
|
69
|
|
|
|
|
70
|
|
|
return Validator::make($data, [ |
|
71
|
|
|
'username' => 'required|max:255', |
|
72
|
|
|
'password' => 'required|min:6', |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Create a new user instance after a valid registration. |
|
78
|
|
|
* |
|
79
|
|
|
* @param array $data |
|
80
|
|
|
* @return User |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function create(array $data) |
|
83
|
|
|
{ |
|
84
|
|
|
return User::create([ |
|
85
|
|
|
'name' => $data['name'], |
|
86
|
|
|
'email' => $data['email'], |
|
87
|
|
|
'password' => bcrypt($data['password']), |
|
88
|
|
|
]); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function showLoginForm() |
|
92
|
|
|
{ |
|
93
|
|
|
return view($this->getView('pages.login')); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// Todo |
|
97
|
|
|
public function showRegistrationForm() |
|
98
|
|
|
{ |
|
99
|
|
|
return view('admin.auth.register'); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.