Passed
Push — dev6 ( bf7d7f...edb7de )
by Ron
17:07
created

ChangePasswordController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 3 1
A store() 0 12 2
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));
1 ignored issue
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $user of App\Events\UserPasswordChanged::__construct() does only seem to accept App\Models\User, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        event(new UserPasswordChanged(/** @scrutinizer ignore-type */ $user));
Loading history...
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