Skip to content

Commit 9ecabcf

Browse files
committed
Update profile
1 parent 592f5f2 commit 9ecabcf

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/Shared/Infrastructure/Service/ImageFileService.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ public function upload(): void
5050
. DIRECTORY_SEPARATOR
5151
. trim($file->getUploadPath(), DIRECTORY_SEPARATOR);
5252

53-
if (! is_dir($targetDir)) {
54-
mkdir($targetDir, 0755, true);
55-
}
56-
57-
@chmod($targetDir, 0777);
58-
5953
if (! is_writable($targetDir)) {
6054
throw new RuntimeException('Upload directory is not writable: ' . $targetDir);
6155
}

src/Template/Presentation/View/Engine/LatteEngine.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ private function registerFunctions(): void
140140
$this->auth->authUser()
141141
);
142142

143+
$this->latte->addFunction('authProfile', fn () =>
144+
$this->auth->authProfile()
145+
);
146+
143147
$this->latte->addFunction('isLoggedIn', fn () =>
144148
$this->auth->isLoggedIn()
145149
);

src/User/Application/Service/AuthService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Delight\Auth\Auth;
66
use Delight\Auth\Role;
77
use Illuminate\Database\Capsule\Manager as Capsule;
8+
use Ivy\User\Domain\Entity\Profile;
89
use Ivy\User\Domain\Entity\User;
910

1011
class AuthService
@@ -42,6 +43,17 @@ public function authUser(): ?User
4243
return User::find($userId);
4344
}
4445

46+
public function authProfile(): ?Profile
47+
{
48+
if (! $this->auth->isLoggedIn()) {
49+
return null;
50+
}
51+
52+
$userId = $this->auth->getUserId();
53+
54+
return Profile::where('user_id', $userId)->first();
55+
}
56+
4557
public function canEditAsEditor(): bool
4658
{
4759
return $this->auth->hasAnyRole(

src/User/Presentation/Controller/ProfileController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,9 @@ function ($selector, $token) use ($result) {
133133
$profile->save();
134134
}
135135

136-
if ($this->request->get('user_image') === 'delete') {
137-
136+
if ($this->request->request->has('delete_user_image')) {
138137
$file = new ImageFile;
139138
$file->setUploadPath('profile')->remove($profile->user_image);
140-
141139
$profile->user_image = null;
142140
$profile->save();
143141
}

src/User/Presentation/Form/ProfileForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected function rules(): array
1616
return [
1717
'username' => ['required', 'not_nullable', new UserNameRule],
1818
'email' => ['required', 'not_nullable', 'email'],
19-
'delete_user_image' => ['bool'],
19+
'delete_user_image' => ['in:delete'],
2020
'user_image' => ['file', new UserImageRule],
2121
];
2222
}

0 commit comments

Comments
 (0)