1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace NukaCode\Users\Http\Controllers;
|
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\BaseController;
|
6
|
|
|
use App\Models\User;
|
7
|
|
|
use Illuminate\Support\Facades\DB;
|
8
|
|
|
use NukaCode\Users\Events\UserLoggedIn;
|
9
|
|
|
use NukaCode\Users\Events\UserRegistered;
|
10
|
|
|
use NukaCode\Users\Http\Requests\Login;
|
11
|
|
|
use NukaCode\Users\Http\Requests\Registration;
|
12
|
|
|
|
13
|
|
|
class AuthController extends BaseController
|
14
|
|
|
{
|
15
|
|
|
/**
|
16
|
|
|
* Display the login form.
|
17
|
|
|
*/
|
18
|
|
|
public function login()
|
19
|
|
|
{
|
20
|
|
|
//
|
21
|
|
|
}
|
22
|
|
|
|
23
|
|
|
/**
|
24
|
|
|
* Log the user in
|
25
|
|
|
*
|
26
|
|
|
* @param Login $request
|
27
|
|
|
*
|
28
|
|
|
* @return mixed
|
29
|
|
|
*/
|
30
|
|
|
public function handleLogin(Login $request)
|
31
|
|
|
{
|
32
|
|
|
// Set the auth data
|
33
|
|
|
$userData = [
|
34
|
|
|
'username' => $request->get('username'),
|
35
|
|
|
'password' => $request->get('password'),
|
36
|
|
|
];
|
37
|
|
|
|
38
|
|
|
// Log in successful
|
39
|
|
|
if (auth()->attempt($userData, $request->get('remember', false))) {
|
40
|
|
|
event(new UserLoggedIn(auth()->user()));
|
|
|
|
|
41
|
|
|
|
42
|
|
|
return redirect()
|
43
|
|
|
->intended(route('home'))
|
44
|
|
|
->with('message', 'You have been logged in.');
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
// Login failed
|
48
|
|
|
return redirect(route('auth.login'))
|
49
|
|
|
->with('errors', ['Your username or password was incorrect.']);
|
50
|
|
|
}
|
51
|
|
|
|
52
|
|
|
/**
|
53
|
|
|
* Display the registration form.
|
54
|
|
|
*/
|
55
|
|
|
public function register()
|
56
|
|
|
{
|
57
|
|
|
//
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
/**
|
61
|
|
|
* Register a user
|
62
|
|
|
*
|
63
|
|
|
* @param Registration $request
|
64
|
|
|
*
|
65
|
|
|
* @return mixed
|
66
|
|
|
*/
|
67
|
|
|
public function handleRegister(Registration $request)
|
68
|
|
|
{
|
69
|
|
|
DB::beginTransaction();
|
70
|
|
|
|
71
|
|
|
try {
|
72
|
|
|
$user = User::create($request->all());
|
73
|
|
|
$user->assignRole(config('users.default'));
|
74
|
|
|
|
75
|
|
|
auth()->login($user);
|
76
|
|
|
|
77
|
|
|
event(new UserRegistered(auth()->user()));
|
|
|
|
|
78
|
|
|
} catch (\Exception $exception) {
|
79
|
|
|
DB::rollBack();
|
80
|
|
|
|
81
|
|
|
return redirect(route('auth.register'))
|
82
|
|
|
->with('errors', $exception->getMessage());
|
83
|
|
|
}
|
84
|
|
|
|
85
|
|
|
DB::commit();
|
86
|
|
|
|
87
|
|
|
return redirect(route('home'))
|
88
|
|
|
->with('message', 'Your account has been created.');
|
89
|
|
|
}
|
90
|
|
|
|
91
|
|
|
/**
|
92
|
|
|
* Log the user out.
|
93
|
|
|
*
|
94
|
|
|
* @return mixed
|
95
|
|
|
*/
|
96
|
|
|
public function logout()
|
97
|
|
|
{
|
98
|
|
|
auth()->logout();
|
99
|
|
|
|
100
|
|
|
return redirect(route('home'))
|
101
|
|
|
->with('message', 'You have been logged out.');
|
102
|
|
|
}
|
103
|
|
|
}
|
104
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: