/** * Test login */ public function login($uid) { $login = TaskerMAN\Application\Login::verifyCredentials($this->email, $this->password); $this->assertInstanceOf('TaskerMAN\\Application\\User', $login); // Verify it's returning the correct stuff $this->assertEquals($login->getID(), $uid); $this->assertEquals($login->getEmail(), $this->email); $this->assertEquals($login->getName(), $this->name); $this->assertEquals($login->isAdmin(), $this->admin); // Check API key is valid $API = TaskerMAN\Application\API::authenticateByToken($login->getAPIToken()); $this->assertTrue($API); }
<?php // Return dashboard stats echo TaskerMAN\Application\API::response(TaskerMAN\Application\DashboardStats::getStats(TaskerMAN\Application\API::$uid));
<?php echo TaskerMAN\Application\API::response('ok');
<?php header('Content-type: application/json'); require_once 'config/init.php'; try { TaskerMAN\Application\API::init(); } catch (TaskerMAN\Application\APIErrorException $e) { die(TaskerMAN\Application\API::error($e->getMessage())); } catch (TaskerMAN\Core\FatalException $e) { die(TaskerMAN\Application\API::error($e->get_json())); }
<?php // Get username and password $email = TaskerMAN\Core\IO::GET('email'); $password = TaskerMAN\Core\IO::GET('password'); if (empty($email) || empty($password)) { throw new TaskerMAN\Application\APIErrorException('Requires email and password'); } // Verify the user's login credentials $user = TaskerMAN\Application\Login::verifyCredentials($email, $password); // Login details incorrect if (!$user) { throw new TaskerMAN\Application\APIErrorException('Incorrect email or password'); } // Login success, return API Token echo TaskerMAN\Application\API::response(array('key' => $user->api_token));
throw new TaskerMAN\Application\APIErrorException('Invalid task ID'); } switch ($status) { // Make sure we're not setting the status to a state it's already in case $task->status: throw new TaskerMAN\Application\APIErrorException('Trying to change status to same value as it already has'); break; // allocated // allocated case 1: $task->setStatus(1); $task->setCompletedTime('0000-00-00 00:00:00'); break; // completed // completed case 2: $task->setStatus(2); $task->setCompletedTime(date("Y-m-d H:i:s", $completed_time)); break; // Invalid status code // Invalid status code default: echo TaskerMAN\Application\API::error('Invalid status value (must be 1 or 2)'); exit; break; } // Commit changes $task->save(); // Return success response echo TaskerMAN\Application\API::response('Success');
<?php // Get array of task IDs $ids = explode(',', TaskerMAN\Core\IO::GET('id')); // Remove non-numeric IDs foreach ($ids as $key => $id) { if (!is_numeric($id)) { unset($ids[$key]); } } $steps = array(); // Loop through each task foreach ($ids as $id) { $task = new TaskerMAN\Application\Task($id); if (is_null($task->id)) { // Unable to load task throw new TaskerMAN\Application\APIErrorException('Task ' . $id . ' does not exist'); } if ((int) $task->assignee_uid !== TaskerMAN\Application\API::$uid) { throw new TaskerMAN\Application\APIErrorException('User does not have access to task ' . $id); } // Load steps into response array $steps[$id] = $task->getSteps(); } if (empty($steps)) { throw new TaskerMAN\Application\APIErrorException('No steps found'); } echo TaskerMAN\Application\API::response(array('steps' => $steps));
<?php $id = (int) TaskerMAN\Core\IO::GET('id'); $comment = TaskerMAN\Core\IO::POST('comment', false); $step = new TaskerMAN\Application\TaskStep($id); if ($step->task_id === NULL) { // Unable to load step, does not exist throw new TaskerMAN\Application\APIErrorException('Unknown step ID'); } // Check that user is permitted to modify this task if ((int) $step->assignee_uid != TaskerMAN\Application\API::$uid) { throw new TaskerMAN\Application\APIErrorException('User does not have access to modify this step'); } // Set comment and commit changes try { $step->setComment($comment); $step->save(); } catch (TaskerMAN\Application\TaskException $e) { throw new TaskerMAN\Application\APIErrorException($e->getMessage()); } echo TaskerMAN\Application\API::response('Step comment updated successfully');
/** * Check that an invalid token won't allow a user to be authenticated * Note that checking of a valid token is performed in UserCreationTest */ public function testInvalidTokenAuthentication() { $token = 'NOT-A-REAL-TOKEN'; $response = TaskerMAN\Application\API::authenticateByToken($token); $this->assertFalse($response); }
<?php $id = (int) TaskerMAN\Core\IO::GET('id'); $task = new TaskerMAN\Application\Task($id); if (is_null($task->id)) { // Unable to load task throw new TaskerMAN\Application\APIErrorException('Task does not exist'); } if ((int) $task->assignee_uid !== TaskerMAN\Application\API::$uid) { throw new TaskerMAN\Application\APIErrorException('User does not have access to this task'); } $result = array('id' => $task->id, 'created_uid' => $task->created_uid, 'created_name' => $task->created_name, 'assignee_uid' => $task->assignee_uid, 'assignee_name' => $task->assignee_name, 'due_by' => $task->due_by, 'completed_time' => $task->completed_time, 'status' => $task->status, 'title' => $task->title, 'steps' => $task->getSteps()); echo TaskerMAN\Application\API::response($result);
<?php // Return all tasks for a specific user TaskerMAN\Application\TaskListInterface::setSearchCriteria('assignee_uid', TaskerMAN\Application\API::$uid); TaskerMAN\Application\TaskListInterface::setStartPosition(0); echo TaskerMAN\Application\API::response(array('tasks' => TaskerMAN\Application\TaskListInterface::getTasks()));