|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\User; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Inertia\Inertia; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
use Illuminate\Support\Facades\Hash; |
|
9
|
|
|
|
|
10
|
|
|
use App\Models\User; |
|
11
|
|
|
use App\Events\UserPasswordChanged; |
|
12
|
|
|
use App\Http\Controllers\Controller; |
|
13
|
|
|
use App\Http\Requests\User\ChangePasswordRequest; |
|
14
|
|
|
|
|
15
|
|
|
class ChangePasswordController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Page for a user to change their own password |
|
19
|
|
|
*/ |
|
20
|
|
|
public function index() |
|
21
|
|
|
{ |
|
22
|
|
|
return Inertia::render('User/ChangePassword'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Show the form for creating a new resource. |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Illuminate\Http\Response |
|
29
|
|
|
*/ |
|
30
|
|
|
// public function create() |
|
31
|
|
|
// { |
|
32
|
|
|
// // |
|
33
|
|
|
// } |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Store a reset password for the logged in user |
|
37
|
|
|
*/ |
|
38
|
|
|
public function store(ChangePasswordRequest $request) |
|
39
|
|
|
{ |
|
40
|
|
|
$user = User::find($request->user()->user_id); |
|
41
|
|
|
$expires = config('auth.passwords.settings.expire') ? Carbon::now()->addDays(config('auth.passwords.settings.expire')) : null; |
|
42
|
|
|
|
|
43
|
|
|
$user->forceFill(['password' => Hash::make($request->password), 'password_expires' => $expires]); |
|
44
|
|
|
$user->save(); |
|
45
|
|
|
|
|
46
|
|
|
event(new UserPasswordChanged($user)); |
|
|
|
|
|
|
47
|
|
|
return redirect(route('dashboard'))->with([ |
|
48
|
|
|
'message' => 'Password successfully updated', |
|
49
|
|
|
'type' => 'success', |
|
50
|
|
|
]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Display the specified resource. |
|
55
|
|
|
* |
|
56
|
|
|
* @param int $id |
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
// public function show($id) |
|
60
|
|
|
// { |
|
61
|
|
|
// // |
|
62
|
|
|
// } |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Show the form for editing the specified resource. |
|
66
|
|
|
* |
|
67
|
|
|
* @param int $id |
|
68
|
|
|
* @return \Illuminate\Http\Response |
|
69
|
|
|
*/ |
|
70
|
|
|
// public function edit($id) |
|
71
|
|
|
// { |
|
72
|
|
|
// // |
|
73
|
|
|
// } |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Update the specified resource in storage. |
|
77
|
|
|
* |
|
78
|
|
|
* @param \Illuminate\Http\Request $request |
|
79
|
|
|
* @param int $id |
|
80
|
|
|
* @return \Illuminate\Http\Response |
|
81
|
|
|
*/ |
|
82
|
|
|
// public function update(Request $request, $id) |
|
83
|
|
|
// { |
|
84
|
|
|
// // |
|
85
|
|
|
// } |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Remove the specified resource from storage. |
|
89
|
|
|
* |
|
90
|
|
|
* @param int $id |
|
91
|
|
|
* @return \Illuminate\Http\Response |
|
92
|
|
|
*/ |
|
93
|
|
|
// public function destroy($id) |
|
94
|
|
|
// { |
|
95
|
|
|
// // |
|
96
|
|
|
// } |
|
97
|
|
|
} |
|
98
|
|
|
|