public static function getValidUserId($token) { $authaccess = new authaccess(); $authaccess->set_variable('authToken', $token); if ($authaccess->load()) { return $authaccess->get_variable('userId'); } throw new Exception('EXPIRED TOKEN'); }
public function login($name, $pwd) { $this->set_variable('username', $name); if ($this->load()) { if ($pwd === $this->get_variable('password')) { $retVal['userId'] = $this->get_variable('userid'); $authaccess = new authaccess(); $retVal['authToken'] = $authaccess->generateToken($retVal['userId']); $retVal['success'] = true; } else { $retVal['errorCode'] = user::PASSWORD_DOES_NOT_MATCH; $retVal['success'] = false; } } else { $retVal['errorCode'] = user::USERNAME_DOES_NOT_EXIST; $retVal['success'] = false; } return $retVal; }
protected function moods($argValues) { if ($this->method == 'GET') { try { $userId = authaccess::getValidUserId($argValues[0]); $history = moodhistory::getLastestMoods($userId, $argValues[1]); return $history; } catch (Exception $e) { return "ERROR - EXPIRED OR INVALID TOKEN"; } } else { if ($this->method == 'POST') { try { $userId = authaccess::getValidUserId($argValues[0]); $history = moodhistory::addMood($userId, $this->input->groupId, $this->input->moodId); return $history; } catch (Exception $e) { return "ERROR - EXPIRED OR INVALID TOKEN"; } } else { return "ERROR - NOT WORKING" . print_r($this->input, true); } } }