summaryrefslogtreecommitdiffstats
path: root/application/controllers
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2016-10-07 12:48:06 +0200
committerFlorian Pritz <bluewind@xinu.at>2016-10-31 09:32:14 +0100
commit67c801e8719456fa9fb920201a7afe28b7d6a64f (patch)
tree3d69ae90792f96d37cb1c7675ea3bb1a48a5573d /application/controllers
parent30dd61eb23d64f26c595ffe5c95d8fc2ee328753 (diff)
Copy api/v1/user to api/v2/user
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers')
-rw-r--r--application/controllers/api/v2/user.php67
1 files changed, 65 insertions, 2 deletions
diff --git a/application/controllers/api/v2/user.php b/application/controllers/api/v2/user.php
index 2a233fe52..655dc62f3 100644
--- a/application/controllers/api/v2/user.php
+++ b/application/controllers/api/v2/user.php
@@ -1,6 +1,6 @@
<?php
/*
- * Copyright 2014-2015 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ * Copyright 2014-2016 Florian "Bluewind" Pritz <bluewind@server-speed.net>
*
* Licensed under AGPLv3
* (see COPYING for full license text)
@@ -8,5 +8,68 @@
*/
namespace controllers\api\v2;
-class user extends \controllers\api\v1\user {
+class user extends \controllers\api\api_controller {
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->load->model('muser');
+ }
+
+ public function apikeys()
+ {
+ $this->muser->require_access("full");
+ return \service\user::apikeys($this->muser->get_userid());
+ }
+
+ public function create_apikey()
+ {
+ $username = $this->input->post("username");
+ $password = $this->input->post("password");
+ if ($username && $password) {
+ if (!$this->muser->login($username, $password)) {
+ throw new \exceptions\NotAuthenticatedException("user/login-failed", "Login failed");
+ }
+ }
+
+ $this->muser->require_access("full");
+
+ $userid = $this->muser->get_userid();
+ $comment = $this->input->post("comment");
+ $comment = $comment === false ? "" : $comment;
+ $access_level = $this->input->post("access_level");
+
+ $key = \service\user::create_apikey($userid, $comment, $access_level);
+
+ return array(
+ "new_key" => $key,
+ );
+ }
+
+ public function delete_apikey()
+ {
+ $this->muser->require_access("full");
+
+ $userid = $this->muser->get_userid();
+ $key = $this->input->post("delete_key");
+
+ $this->db->where('user', $userid)
+ ->where('key', $key)
+ ->delete('apikeys');
+
+ $affected = $this->db->affected_rows();
+
+ assert($affected >= 0 && $affected <= 1);
+ if ($affected == 1) {
+ return array(
+ "deleted_keys" => array(
+ $key => array (
+ "key" => $key,
+ ),
+ ),
+ );
+ } else {
+ throw new \exceptions\PublicApiException('user/delete_apikey/failed', 'Apikey deletion failed. Possibly wrong owner.');
+ }
+ }
}