aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/admin/src
diff options
context:
space:
mode:
authorMarvin Borner2018-05-09 23:15:02 +0200
committerMarvin Borner2018-05-09 23:15:02 +0200
commit6540ea037ea6331a013c928a1dd15b8f5de8b30f (patch)
treecbc1c4f161d207fb2c01aa3311bfbf325b448aa1 /main/app/sprinkles/admin/src
parent40f3846c01848f851078e809aac4b9268036f4b2 (diff)
Began person verifying chat integration (names is chat home etc)
Diffstat (limited to 'main/app/sprinkles/admin/src')
-rw-r--r--main/app/sprinkles/admin/src/Controller/WormholeController.php47
1 files changed, 29 insertions, 18 deletions
diff --git a/main/app/sprinkles/admin/src/Controller/WormholeController.php b/main/app/sprinkles/admin/src/Controller/WormholeController.php
index 7c35e55..2ed7e68 100644
--- a/main/app/sprinkles/admin/src/Controller/WormholeController.php
+++ b/main/app/sprinkles/admin/src/Controller/WormholeController.php
@@ -31,13 +31,7 @@ use Illuminate\Session\FileSessionHandler;
class WormholeController extends SimpleController
{
public function verify(Request $request, Response $response, $args) {
- $currentUser = $this->ci->currentUser; // FOR DATABASE QUERY
-
- $access_token = $args['access_token'];
- if (DB::table('public_keys')
- ->where('UserID', 1)
- ->where('Key', '=', $access_token)
- ->exists()) {
+ if ($this->verifyAccessToken($args)) {
$user_id = $args['user_id'];
$session_id = $args['session_id'];
$session_file = file_get_contents("../app/sessions/" . $session_id);
@@ -47,20 +41,26 @@ class WormholeController extends SimpleController
} else {
throw new NotFoundException();
}
- } else {
- throw new NotFoundException(); // IT'S A FORBIDDEN EXCEPTION BUT IT'S SECRET! PSSSHT
}
}
- public function getInfo(Request $request, Response $response, $args) {
- $currentUser = $this->ci->currentUser; // FOR DATABASE QUERY
+ public function newMessage(Request $request, Response $response, $args) {
+ if ($this->verifyAccessToken($args)) {
+ $sender_id = $args['sender_id'];
+ $receiver_id = $args['receiver_id'];
+ $message = $args['message'];
+ if (($sender_id != $receiver_id) && $message) {
+ DB::table('chat_messages')
+ ->insert(['sender_id' => $sender_id, 'receiver_id' => $receiver_id, 'message' => $message]);
+ return $response->withStatus(200);
+ } else {
+ throw new BadRequestException();
+ }
+ }
+ }
- $access_token = $args['access_token'];
- if (DB::table('public_keys')
- ->where('UserID', 1)
- ->where('Key', '=', $access_token)
- ->exists()) {
- $classMapper = $this->ci->classMapper;
+ public function getInfo(Request $request, Response $response, $args) {
+ if ($this->verifyAccessToken($args)) {
$user = DB::table('users')
->where('id', $args["user_id"])
->first();
@@ -77,8 +77,19 @@ class WormholeController extends SimpleController
$result = $user->toArray();
$result["avatar"] = $user->avatar;
return $response->withJson($result, 200, JSON_PRETTY_PRINT);
+ }
+ }
+
+ private function verifyAccessToken($args) {
+ $currentUser = $this->ci->currentUser; // FOR DATABASE QUERY
+ $access_token = $args['access_token'];
+ if (DB::table('public_keys')
+ ->where('UserID', 1)
+ ->where('Key', '=', $access_token)
+ ->exists()) {
+ return true;
} else {
- throw new NotFoundException(); // IT'S A FORBIDDEN EXCEPTION BUT IT'S SECRET! PSSSHT
+ throw new NotFoundException();
}
}
} \ No newline at end of file