diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-01-15 14:50:10 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-01-15 14:50:10 +0100 |
commit | 2d0da0b920035c90d56db5dbec6d62f5b50ba0c2 (patch) | |
tree | e2303e59a05dd24b100d9bc35b1409f00d68aa6e /src/gemini/Controller | |
parent | 254eb4a9959e4c281fdeb47378a654de978cb1e4 (diff) |
account management
Diffstat (limited to 'src/gemini/Controller')
-rw-r--r-- | src/gemini/Controller/User.php | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/src/gemini/Controller/User.php b/src/gemini/Controller/User.php index a870b88..bc882b0 100644 --- a/src/gemini/Controller/User.php +++ b/src/gemini/Controller/User.php @@ -3,7 +3,10 @@ namespace App\gemini\Controller; use App\DB; +use App\View; use GeminiFoundation\Request; +use GeminiFoundation\Response; +use GeminiFoundation\Status; class User { @@ -33,7 +36,7 @@ class User 'email' => '(no email)', ] ); - $userId = DB::query('select id from users where password=:password', ['password' => $request->getClientCertificate()->getFingerprint()])->fetchColumn(); + $userId = DB::$connection->lastInsertId(); DB::query( 'insert into users_gemini (certificate, user_id) values (:fingerprint, :userId)', @@ -54,7 +57,7 @@ class User 'satisfaction' => 100, ] ); - $villageId = DB::query('select id from villages order by id desc limit 1')->fetchColumn(); + $villageId = DB::$connection->lastInsertId(); DB::query( 'insert into user_villages (user_id, village_id) values (:userId, :villageId)', @@ -115,4 +118,66 @@ class User return $this->get($request); } + + public function account(Request $request): Response + { + $user = $this->get($request); + + + return new Response(body: View::render('account.twig', [ + 'user' => $user, + ])); + } + + public function accountUsername(Request $request): Response + { + $input = $request->get('input'); + if (empty($input)) { + return new Response(statusCode: Status::INPUT, meta: 'Username'); + } + + $user = $this->get($request); + DB::query('update users set username=:username where id=:id', ['username' => urldecode($input), 'id' => $user['id']]); + + + return new Response( + statusCode: Status::REDIRECT_TEMPORARY, + meta: '/account' + ); + } + + public function accountEmail(Request $request): Response + { + $input = $request->get('input'); + if (empty($input)) { + return new Response(statusCode: Status::INPUT, meta: 'E-Mail'); + } + + $user = $this->get($request); + DB::query('update users set email=:email where id=:id', ['email' => urldecode($input), 'id' => $user['id']]); + + + return new Response( + statusCode: Status::REDIRECT_TEMPORARY, + meta: '/account' + ); + } + + public function accountPassword(Request $request): Response + { + $input = $request->get('input'); + if (empty($input)) { + return new Response(statusCode: Status::SENSITIVE_INPUT, meta: 'Password'); + } + + $password = password_hash(urldecode($input), PASSWORD_DEFAULT); + $user = $this->get($request); + DB::query('update users set password=:password where id=:id', ['password' => $password, 'id' => $user['id']]); + + + return new Response( + statusCode: Status::REDIRECT_TEMPORARY, + meta: '/account' + ); + } } |