From 8fd7c6c2ab80240ab1d163c9a4134822c7524144 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 11 Jan 2015 01:40:07 +0100 Subject: add initial user api Signed-off-by: Florian Pritz --- application/controllers/user.php | 42 +++------------------------------------- 1 file changed, 3 insertions(+), 39 deletions(-) (limited to 'application/controllers/user.php') diff --git a/application/controllers/user.php b/application/controllers/user.php index a702b63c7..62569e1f1 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -91,24 +91,7 @@ class User extends MY_Controller { $access_level = "apikey"; } - $valid_levels = $this->muser->get_access_levels(); - if (array_search($access_level, $valid_levels) === false) { - show_error("Invalid access levels requested."); - } - - if (strlen($comment) > 255) { - show_error("Comment may only be 255 chars long."); - } - - $key = random_alphanum(32); - - $this->db->set(array( - 'key' => $key, - 'user' => $userid, - 'comment' => $comment, - 'access_level' => $access_level - )) - ->insert('apikeys'); + $key = \service\user::create_apikey($userid, $comment, $access_level); if (static_storage("response_type") == "json") { return send_json_reply(array("new_key" => $key)); @@ -140,27 +123,8 @@ class User extends MY_Controller { $this->muser->require_access(); $userid = $this->muser->get_userid(); - - $query = $this->db->select('key, created, comment, access_level') - ->from('apikeys') - ->where('user', $userid) - ->order_by('created', 'desc') - ->get()->result_array(); - - // Convert timestamp to unix timestamp - // TODO: migrate database to integer timestamp and get rid of this - foreach ($query as &$record) { - if (!empty($record['created'])) { - $record['created'] = strtotime($record['created']); - } - } - unset($record); - - if (static_storage("response_type") == "json") { - return send_json_reply($query); - } - - $this->data["query"] = $query; + $apikeys = \service\user::apikeys($userid); + $this->data["query"] = $apikeys; $this->load->view('header', $this->data); $this->load->view($this->var->view_dir.'apikeys', $this->data); -- cgit v1.2.3-24-g4f1b From d9c895ce4f53b180fc11c3b5a172c4cf787b1279 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 11:18:28 +0100 Subject: Remove unstable json api Signed-off-by: Florian Pritz --- application/controllers/user.php | 9 --------- 1 file changed, 9 deletions(-) (limited to 'application/controllers/user.php') diff --git a/application/controllers/user.php b/application/controllers/user.php index 62569e1f1..aba2a8ec1 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -8,11 +8,6 @@ */ class User extends MY_Controller { - protected $json_enabled_functions = array( - "create_apikey", - "apikeys", - ); - function __construct() { @@ -93,10 +88,6 @@ class User extends MY_Controller { $key = \service\user::create_apikey($userid, $comment, $access_level); - if (static_storage("response_type") == "json") { - return send_json_reply(array("new_key" => $key)); - } - if (is_cli_client()) { echo "$key\n"; } else { -- cgit v1.2.3-24-g4f1b From a842392c30e9ef1d1d2bd9b4eb271c3fd23b853f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 3 Feb 2015 17:17:27 +0100 Subject: Use exceptions instead of show_error Signed-off-by: Florian Pritz --- application/controllers/user.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'application/controllers/user.php') diff --git a/application/controllers/user.php b/application/controllers/user.php index aba2a8ec1..5b4e85141 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -136,7 +136,7 @@ class User extends MY_Controller { ->count_all_results(); if ($invitations + 1 > 3) { - show_error("You can't create more invitation keys at this time."); + throw new \exceptions\PublicApiException("user/invitation-limit", "You can't create more invitation keys at this time."); } $key = random_alphanum(12, 16); @@ -277,7 +277,7 @@ class User extends MY_Controller { $username = $this->input->post("username"); if (!$this->muser->username_exists($username)) { - show_error("Invalid username"); + throw new \exceptions\PublicApiException("user/reset_password/invalid-username", "Invalid username"); } $userinfo = $this->db->select('id, email, username') @@ -388,18 +388,18 @@ class User extends MY_Controller { $values = explode("-", $value); if (!is_array($values) || count($values) != 2) { - show_error("Invalid upload id limit value"); + throw new \exceptions\PublicApiException("user/profile/invalid-upload-id-limit", "Invalid upload id limit value"); } $lower = intval($values[0]); $upper = intval($values[1]); if ($lower > $upper) { - show_error("lower limit > upper limit"); + throw new \exceptions\PublicApiException("user/profile/lower-bigger-than-upper", "lower limit > upper limit"); } if ($lower < 3 || $upper > 64) { - show_error("upper or lower limit out of bounds (3-64)"); + throw new \exceptions\PublicApiException("user/profile/limit-out-of-bounds", "upper or lower limit out of bounds (3-64)"); } return $lower."-".$upper; -- cgit v1.2.3-24-g4f1b From d7fc5f46a8b6faec4ec0c18089d94d21e505c36c Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 14 Feb 2015 19:13:26 +0100 Subject: Use assoc array for service/user/apikeys Signed-off-by: Florian Pritz --- application/controllers/user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application/controllers/user.php') diff --git a/application/controllers/user.php b/application/controllers/user.php index 5b4e85141..33d0efb6b 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -115,7 +115,7 @@ class User extends MY_Controller { $userid = $this->muser->get_userid(); $apikeys = \service\user::apikeys($userid); - $this->data["query"] = $apikeys; + $this->data["query"] = $apikeys["apikeys"]; $this->load->view('header', $this->data); $this->load->view($this->var->view_dir.'apikeys', $this->data); -- cgit v1.2.3-24-g4f1b