add profile routs

This commit is contained in:
2024-12-27 15:16:21 +03:00
parent 1a54003030
commit 7489e999ef
4 changed files with 176 additions and 2 deletions

View File

@ -150,7 +150,47 @@ class UserController extends AdminController
if (!$user){
throw new Exception(message: "The user not found");
}
$this->cgView->render("view.php", ['user' => $user]);
$this->cgView->render("view_profile.php", ['user' => $user]);
}
public function actionProfileUpdate(): void
{
$model = UserService::getAuthUser();
if (!$model){
throw new Exception(message: "The user not found");
}
$this->cgView->render("form_profile.php", ['model' => $model]);
}
public function actionProfileEdit(): void
{
$user = UserService::getAuthUser();
if (!$user){
throw new Exception(message: "The user not found");
}
$userForm = new CreateUserForm();
$userService = new UserService();
$userForm->load($_REQUEST);
if (isset($_FILES['user_photo']) && $_FILES['user_photo']['error'] === UPLOAD_ERR_OK) {
$file = new FileUpload($_FILES['user_photo'], ['jpg', 'jpeg', 'png']);
$file->upload();
$userForm->setItem('user_photo', $file->getUploadFile());
}
if ($userForm->validateForUpdate()){
$user = $userService->update($userForm, $user);
$entityRelation = new EntityRelation();
$entityRelation->saveEntityRelation(entity: "user", model: $user, request: new Request());
if ($user){
$this->redirect("/admin/user/profile");
}
}
$this->redirect("/admin/user/profile/update");
}
}