|
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
|
|
|
use App\Http\Requests\User\ChangeUserPasswordRequest; |
|
15
|
|
|
|
|
16
|
|
|
class ChangePasswordController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Page for a user to change their own password |
|
20
|
|
|
*/ |
|
21
|
|
|
public function index() |
|
22
|
|
|
{ |
|
23
|
|
|
return Inertia::render('User/ChangePassword'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Store a reset password for the logged in user |
|
28
|
|
|
*/ |
|
29
|
|
|
public function store(ChangePasswordRequest $request) |
|
30
|
|
|
{ |
|
31
|
|
|
$user = User::find($request->user()->user_id); |
|
32
|
|
|
$expires = config('auth.passwords.settings.expire') ? Carbon::now()->addDays(config('auth.passwords.settings.expire')) : null; |
|
33
|
|
|
|
|
34
|
|
|
$user->forceFill(['password' => Hash::make($request->password), 'password_expires' => $expires]); |
|
35
|
|
|
$user->save(); |
|
36
|
|
|
|
|
37
|
|
|
event(new UserPasswordChanged($user)); |
|
|
|
|
|
|
38
|
|
|
return redirect(route('dashboard'))->with([ |
|
39
|
|
|
'message' => 'Password successfully updated', |
|
40
|
|
|
'type' => 'success', |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Update the password for a specific user |
|
46
|
|
|
*/ |
|
47
|
|
|
public function update(ChangeUserPasswordRequest $request, $id) |
|
48
|
|
|
{ |
|
49
|
|
|
$expires = config('auth.passwords.settings.expire') ? Carbon::now()->addDays(config('auth.passwords.settings.expire')) : null; |
|
50
|
|
|
$user = User::where('username', $id)->firstOrFail(); |
|
51
|
|
|
|
|
52
|
|
|
$user->forceFill(['password' => Hash::make($request->password), 'password_expires' => $expires]); |
|
53
|
|
|
$user->save(); |
|
54
|
|
|
|
|
55
|
|
|
event(new UserPasswordChanged($user)); |
|
56
|
|
|
return back()->with([ |
|
57
|
|
|
'message' => 'Password successfully updated', |
|
58
|
|
|
'type' => 'success', |
|
59
|
|
|
]); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|