Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 268df0b

Browse files
committed
split user save and password save
1 parent 84f8bbd commit 268df0b

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

README.md

-11
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,6 @@ class MyUser extends \LLoadoutInforce\Http\Livewire\User
110110
];
111111
}
112112

113-
public function saveUser()
114-
{
115-
$this->validate();
116-
117-
$this->handlePassword();
118-
$this->user->save();
119-
$this->user->syncRoles([$this->userRoles]);
120-
121-
}
122-
123-
124113
}
125114

126115
```

resources/views/user-ui/user.blade.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</x-jet-form-section>
6161
<x-jet-section-border/>
6262

63-
<x-jet-form-section submit="updateUser">
63+
<x-jet-form-section submit="updatePassword">
6464
<x-slot name="title">
6565
{{ __('Password') }}
6666
</x-slot>
@@ -72,13 +72,13 @@
7272
<x-slot name="form">
7373
<div class="col-span-6 sm:col-span-4">
7474
<x-jet-label for="password" value="{{ __('Password') }}"/>
75-
<x-jet-input id="password" type="password" class="mt-1 block w-full" wire:model.defer="user.password" autocomplete="name"/>
76-
<x-jet-input-error for="user.password" class="mt-2"/>
75+
<x-jet-input id="password" type="password" class="mt-1 block w-full" wire:model.defer="credentials.password" autocomplete="name"/>
76+
<x-jet-input-error for="credentials.password" class="mt-2"/>
7777
</div>
7878
<div class="col-span-6 sm:col-span-4">
7979
<x-jet-label for="password_confirmation" value="{{ __('Confirm password') }}"/>
80-
<x-jet-input id="password_confirmation" type="password" class="mt-1 block w-full" wire:model.defer="user.password_confirmation" autocomplete="name"/>
81-
<x-jet-input-error for="user.password_confirmation" class="mt-2"/>
80+
<x-jet-input id="password_confirmation" type="password" class="mt-1 block w-full" wire:model.defer="credentials.password_confirmation" autocomplete="name"/>
81+
<x-jet-input-error for="credentials.password_confirmation" class="mt-2"/>
8282
</div>
8383
</x-slot>
8484
<x-slot name="actions">

src/Http/Livewire/User.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace LLoadoutInforce\Http\Livewire;
44

5-
use Hash;
5+
use Illuminate\Support\Facades\Auth;
66
use Livewire\Component;
77
use LLoadoutInforce\Http\Livewire\Traits\HandlesPermissions;
88
use LLoadoutInforce\Http\Livewire\Traits\ShowPerks;
@@ -13,15 +13,14 @@ class User extends Component
1313
use HandlesPermissions, ShowPerks;
1414

1515
public $user;
16+
public $credentials;
1617
public $userRoles = [];
1718

1819
protected function rules()
1920
{
2021
return [
2122
'user.name' => 'required|string',
2223
'user.email' => ['required', 'email', 'not_in:' . $this->user->id],
23-
'user.password' => 'required|confirmed',
24-
'user.password_confirmation' => 'required'
2524
];
2625
}
2726

@@ -47,17 +46,24 @@ public function updateUser()
4746
{
4847
$this->validate();
4948

50-
$this->handlePassword();
5149
$this->user->save();
5250
$this->user->syncRoles([$this->userRoles]);
5351

5452
}
5553

56-
private function handlePassword()
54+
public function updatePassword()
5755
{
58-
$this->user->password = Hash::make($this->user->password);
59-
//TODO : maybe this can be done better , remove because otherwise stored to db
60-
unset($this->user->password_confirmation);
56+
$validatedData = $this->validate([
57+
'credentials.password' => 'required|confirmed',
58+
'credentials.password_confirmation' => 'required'
59+
]);
60+
$this->user->forceFill([
61+
'password' => \Illuminate\Support\Facades\Hash::make($this->credentials['password']),
62+
])->save();
63+
Auth::login($this->user);
64+
6165
}
6266

67+
68+
6369
}

0 commit comments

Comments
 (0)