/** performs standard authentication, authorizing the relevant token if necessary */
 public function actionAuthenticate()
 {
     $u = parent::actionAuthenticate();
     if (isset($u)) {
         try {
             //update oauth token
             $tok_str = $this->params->stringParam("oauth_token");
             if (empty($tok_str)) {
                 DTLog::error("OAuth token parameter was empty.");
             }
             $token = new DTOAuthToken($this->db->where("token='{$tok_str}' AND type=0"));
             return $this->authorizeToken($token, $u);
         } catch (Exception $e) {
             DTLog::Debug("auth error: " . $e->getMessage());
         }
         //the user failed to authenticate (maybe bad user/pass)
     }
     return $u;
 }
 /** performs standard authentication, authorizing the relevant token if necessary */
 public function actionAuthenticate()
 {
     $u = parent::actionAuthenticate();
     if (isset($u)) {
         try {
             //create oauth token
             $token = DTOAuthToken::upsert($this->db->qb()->fail(), array("type" => 0, "status" => 1, "user_id" => $u["id"]));
             $redirect_uri = $this->params->stringParam("redirect_uri");
             $state = $this->params->stringParam("state");
             $url = $this->appendParams($redirect_uri, array("code" => $token["token"], "state" => $state));
             DTLog::debug($url);
             header('HTTP/1.1 278 Client Redirect', true, 278);
             return array("location" => $url);
         } catch (Exception $e) {
             DTLog::Debug("auth error: " . $e->getMessage());
         }
         //the user failed to authenticate (maybe bad user/pass)
     }
     return $u;
 }