From c0e65d0446f928b30eecc858c5cf9a8eb1a364c1 Mon Sep 17 00:00:00 2001 From: winter Date: Sat, 18 Jan 2025 16:01:25 +0000 Subject: implement profile editing --- routes/actor_profile_fragment.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'routes/actor_profile_fragment.php') diff --git a/routes/actor_profile_fragment.php b/routes/actor_profile_fragment.php index a3be976..0a07924 100644 --- a/routes/actor_profile_fragment.php +++ b/routes/actor_profile_fragment.php @@ -1,8 +1,14 @@ mount('/fragment/actor/:id', function (array $args) { + render_template('actor_profile', ['actor' => Actor::find($args['id'])]); +}); Router::getInstance()->mount('/fragment/actor/:id/followButton', function (array $args) { $user = UserAccount::requireByCurrentSession(); @@ -38,4 +44,30 @@ Router::getInstance()->mount('/fragment/actor/:id/rejectPending', function (arra $user->actor->rejectPendingFollowFrom($actor); render_template('actor_profile_pending_follow', ['response' => 'rejected']); +}); + +Router::getInstance()->mount('/fragment/profile', function (array $args) { + $user = UserAccount::requireByCurrentSession(); + $actor = $user->actor; + if (isset($_POST['displayName'])) { + // save changes and put the normal profile back + $actor->displayName = trim($_POST['displayName']); + if (strlen($actor->displayName) <= 0) { + $actor->displayName = $actor->handle; + } + $actor->bio = trim($_POST['bio'] ?? ''); + + if (isset($_FILES['avatar'])) { + // TODO: allow using other backends + $obj = StorageObject::createFromUpload(FilesystemStorage::class, $_FILES['avatar']); + $actor->avatar = $obj->getUrl(); + } + + $actor->save(); + $actor->publish(); + + render_template('actor_profile', ['actor' => $actor]); + } else { + render_template('actor_profile_editable', ['actor' => $actor]); + } }); \ No newline at end of file -- cgit v1.3