aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/actor_profile_fragment.php
diff options
context:
space:
mode:
Diffstat (limited to 'routes/actor_profile_fragment.php')
-rw-r--r--routes/actor_profile_fragment.php32
1 files changed, 32 insertions, 0 deletions
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 @@
<?php
use Digitigrade\Model\Actor;
+use Digitigrade\Model\StorageObject;
use Digitigrade\Model\UserAccount;
use Digitigrade\Router;
+use Digitigrade\StorageProvider\FilesystemStorage;
+
+Router::getInstance()->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