1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace NukaCode\Users\Http\Controllers;
|
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\BaseController;
|
6
|
|
|
use App\Models\User;
|
7
|
|
|
use NukaCode\Users\Http\Requests\Login;
|
8
|
|
|
use NukaCode\Users\Http\Requests\Registration;
|
9
|
|
|
|
10
|
|
|
class AuthController extends BaseController
|
11
|
|
|
{
|
12
|
|
|
/**
|
13
|
|
|
* Display the login form.
|
14
|
|
|
*/
|
15
|
|
|
public function login()
|
16
|
|
|
{
|
17
|
|
|
//
|
18
|
|
|
}
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* Log the user in
|
22
|
|
|
*
|
23
|
|
|
* @param Login $request
|
24
|
|
|
*
|
25
|
|
|
* @return mixed
|
26
|
|
|
*/
|
27
|
|
|
public function handleLogin(Login $request)
|
28
|
|
|
{
|
29
|
|
|
// Set the auth data
|
30
|
|
|
$userData = [
|
31
|
|
|
'username' => $request->get('username'),
|
32
|
|
|
'password' => $request->get('password'),
|
33
|
|
|
];
|
34
|
|
|
|
35
|
|
|
// Log in successful
|
36
|
|
|
if (auth()->attempt($userData, $request->get('remember', false))) {
|
37
|
|
|
return redirect()
|
38
|
|
|
->intended('home')
|
39
|
|
|
->with('message', 'You have been logged in.');
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
// Login failed
|
43
|
|
|
return redirect(route('login'))
|
44
|
|
|
->with('errors', ['Your username or password was incorrect.']);
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* Display the registration form.
|
49
|
|
|
*/
|
50
|
|
|
public function register()
|
51
|
|
|
{
|
52
|
|
|
//
|
53
|
|
|
}
|
54
|
|
|
|
55
|
|
|
/**
|
56
|
|
|
* Register a user
|
57
|
|
|
*
|
58
|
|
|
* @param Registration $request
|
59
|
|
|
*
|
60
|
|
|
* @return mixed
|
61
|
|
|
*/
|
62
|
|
|
public function handleRegister(Registration $request)
|
63
|
|
|
{
|
64
|
|
|
try {
|
65
|
|
|
$user = User::create($request->all());
|
66
|
|
|
$user->assignRole(config('nukacode-user.default'));
|
67
|
|
|
|
68
|
|
|
auth()->login($user);
|
69
|
|
|
} catch (\Exception $exception) {
|
70
|
|
|
return redirect('auth.register')
|
71
|
|
|
->with('errors', $exception->getMessage());
|
72
|
|
|
}
|
73
|
|
|
|
74
|
|
|
return redirect(route('home'))
|
75
|
|
|
->with('message', 'Your account has been created.');
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
/**
|
79
|
|
|
* Log the user out.
|
80
|
|
|
*
|
81
|
|
|
* @return mixed
|
82
|
|
|
*/
|
83
|
|
|
public function logout()
|
84
|
|
|
{
|
85
|
|
|
auth()->logout();
|
86
|
|
|
|
87
|
|
|
return redirect(route('home'))
|
88
|
|
|
->with('message', 'You have been logged out.');
|
89
|
|
|
}
|
90
|
|
|
} |