From a8d37fab30ccbced5ec8819510ee84893460bb5e Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 10 May 2018 20:42:13 +0200 Subject: Began chat encrpytion integration and ECC key generation on registration --- .../admin/src/Controller/UserController.php | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'main/app/sprinkles/admin/src/Controller/UserController.php') diff --git a/main/app/sprinkles/admin/src/Controller/UserController.php b/main/app/sprinkles/admin/src/Controller/UserController.php index 46d0f0f..30a8d30 100644 --- a/main/app/sprinkles/admin/src/Controller/UserController.php +++ b/main/app/sprinkles/admin/src/Controller/UserController.php @@ -231,6 +231,32 @@ class UserController extends SimpleController return $response->withStatus(200); } + + /** + * Sets the users public key + * Request type: POST + */ + public function setPublicKey($request, $response, $args) { + $user = $this->getUserFromParams($args); + + if (!$user) { + throw new NotFoundException($request, $response); + } + + $classMapper = $this->ci->classMapper; + $requestedUser = $classMapper->staticMethod('user', 'where', 'user_name', $args['user_name']) + ->first(); + + if ($user->id === $requestedUser->id) { + $PublicKey = $request->getParsedBody()["PublicKey"]; + Capsule::table('public_keys') + ->insert(['UserID' => $requestedUser->id, 'Key' => $PublicKey]); + return $response->withStatus(200); + } else { + throw new ForbiddenException(); + } + } + /** * Processes the request to delete an existing user. * -- cgit v1.2.3