summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gemini/Controller/User.php69
-rw-r--r--src/gemini/Gemini.php34
-rw-r--r--views/gemini/account.twig12
-rw-r--r--views/gemini/footer.twig1
4 files changed, 114 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'
+ );
+ }
}
diff --git a/src/gemini/Gemini.php b/src/gemini/Gemini.php
index 4567958..9d34b30 100644
--- a/src/gemini/Gemini.php
+++ b/src/gemini/Gemini.php
@@ -94,6 +94,20 @@ class Gemini
$response = $buildingController->levelUp($request);
}
+ else if (preg_match('@village/(\d+)/(\d+)/building/(\w+)/manage@', $request->getPath(), $routeMatch)) {
+ $request
+ ->set('x', $routeMatch[1])
+ ->set('y', $routeMatch[2])
+ ->set('type', $routeMatch[3]);
+
+ if ($request->get('type') === 'Storage') {
+ $response = new Response(
+ statusCode: Status::REDIRECT_PERMANENT,
+ meta: "/village/{$routeMatch[1]}/{$routeMatch[2]}/storage/config"
+ );
+ }
+ }
+
else if (preg_match('@village/(\d+)/(\d+)/unit/(\w+)/create@', $request->getPath(), $routeMatch)) {
$request
->set('x', $routeMatch[1])
@@ -189,6 +203,26 @@ class Gemini
$response = $eventController->cancel($request);
}
+ else if (preg_match('@account/username@', $request->getPath(), $routeMatch)) {
+ $userController = new User();
+ $response = $userController->accountUsername($request);
+ }
+
+ else if (preg_match('@account/email@', $request->getPath(), $routeMatch)) {
+ $userController = new User();
+ $response = $userController->accountEmail($request);
+ }
+
+ else if (preg_match('@account/password@', $request->getPath(), $routeMatch)) {
+ $userController = new User();
+ $response = $userController->accountPassword($request);
+ }
+
+ else if (preg_match('@account$@', $request->getPath(), $routeMatch)) {
+ $userController = new User();
+ $response = $userController->account($request);
+ }
+
return $response;
});
diff --git a/views/gemini/account.twig b/views/gemini/account.twig
new file mode 100644
index 0000000..39b889f
--- /dev/null
+++ b/views/gemini/account.twig
@@ -0,0 +1,12 @@
+=> /villages Overview
+
+# Account
+
+Username: {{ user.username }}
+E-Mail: {{ user.email }}
+
+=> /account/username Change Username
+=> /account/email Change E-Mail
+=> /account/password Change Password
+
+{% include 'footer.twig' %}
diff --git a/views/gemini/footer.twig b/views/gemini/footer.twig
index 6784124..614e8d9 100644
--- a/views/gemini/footer.twig
+++ b/views/gemini/footer.twig
@@ -1,5 +1,6 @@
# _ _ _ _
Logged in as {{ session.user.username }}
+=> /account Account
Server Time: {{ 'now' | date('c') }}