Skip to content

Commit 2101b9c

Browse files
committed
Password hashing
1 parent 65e0435 commit 2101b9c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Http/Controllers/ProfileUpdateController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Binaryk\LaravelRestify\Http\Controllers;
44

55
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
6+
use Illuminate\Support\Facades\Hash;
67

78
class ProfileUpdateController extends RepositoryController
89
{
@@ -12,8 +13,15 @@ public function __invoke(RestifyRequest $request)
1213

1314
$request->validate([
1415
'email' => 'sometimes|required|unique:users,email,except,'.$user->id,
16+
'password' => 'sometimes|required|min:5|confirmed',
1517
]);
1618

19+
if ($request->has('password')) {
20+
$request->merge([
21+
'password' => Hash::make($request->get('password')),
22+
]);
23+
}
24+
1725
$user->update($request->only($user->getFillable()));
1826

1927
return $this->response()->data($user->fresh());

tests/Controllers/ProfileControllerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Binaryk\LaravelRestify\Tests\Fixtures\User\User;
66
use Binaryk\LaravelRestify\Tests\IntegrationTest;
77
use Illuminate\Http\UploadedFile;
8+
use Illuminate\Support\Facades\Hash;
89
use Illuminate\Support\Facades\Storage;
910

1011
class ProfileControllerTest extends IntegrationTest
@@ -46,6 +47,20 @@ public function test_profile_update()
4647
]);
4748
}
4849

50+
public function test_profile_update_password()
51+
{
52+
$this->putJson('restify-api/profile', [
53+
'email' => '[email protected]',
54+
'name' => 'Eduard',
55+
'password' => 'secret',
56+
'password_confirmation' => 'secret',
57+
])
58+
->assertStatus(200);
59+
60+
$this->assertTrue(Hash::check('secret', $this->authenticatedAs->password));
61+
62+
}
63+
4964
public function test_profile_update_unique_email()
5065
{
5166
factory(User::class)->create([

0 commit comments

Comments
 (0)