fix namespaces
This commit is contained in:
parent
c9e9bd0f6f
commit
3eeaa208b4
17
Readme
17
Readme
|
@ -2,8 +2,15 @@ adds json APIs to the forum
|
|||
|
||||
add this application to your forum, enable it. the following URLs/methods will now be accessible to you:
|
||||
|
||||
/api/category
|
||||
/api/discussion (GET: id, limit, offset)
|
||||
/api/discussion/add (POST:Discussion/CategoryID, Discussion/Body, Discussion/Name, Discussion/TransientKey)
|
||||
/api/comment/add (POST: Comment/DiscussionID, Comment/CategoryID, Comment/Body, Comment/Name, Comment/TransientKey)
|
||||
/api/session
|
||||
/api/loginapi (GET: user, pass)
|
||||
|
||||
/api/categoryapi
|
||||
|
||||
/api/discussionapi (GET: id, limit, offset)
|
||||
|
||||
/api/discussionapi/add (POST:CategoryID, Body, Name, TransientKey, UserID)
|
||||
/api/discussionapi/remove (POST:CategoryID, DiscussionID, TransientKey, UserID)
|
||||
|
||||
/api/commentapi/add (POST: DiscussionID, CategoryID, Body, Name, TransientKey)
|
||||
|
||||
/api/sessionapi
|
||||
|
|
|
@ -13,12 +13,13 @@ class APIController extends Gdn_Controller {
|
|||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
public function Initialize()
|
||||
{
|
||||
parent::Initialize();
|
||||
|
||||
|
||||
$this->_DeliveryMethod = DELIVERY_METHOD_JSON;
|
||||
//$this->SetHeader("Content-Type", "application/json; charset=utf-8");
|
||||
$this->SetHeader("Content-Type", "text/plain; charset=utf-8");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php if (!defined('APPLICATION')) exit();
|
||||
|
||||
class CategoryController extends APIController
|
||||
class CategoryAPIController extends APIController
|
||||
{
|
||||
public $Uses = array('Gdn_Format', 'Database', 'CategoryModel', 'DiscussionModel');
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php if (!defined('APPLICATION')) exit();
|
||||
|
||||
class CommentController extends APIController
|
||||
class CommentAPIController extends APIController
|
||||
{
|
||||
public $Uses = array('Form', 'Database', 'CategoryModel', 'DiscussionModel', 'CommentModel');
|
||||
|
|
@ -1,11 +1,21 @@
|
|||
<?php if (!defined('APPLICATION')) exit();
|
||||
|
||||
class DiscussionController extends APIController
|
||||
class DiscussionAPIController extends APIController
|
||||
{
|
||||
public $Uses = array('Form', 'Database', 'CategoryModel', 'DiscussionModel', 'CommentModel');
|
||||
public $Uses = array('Form', 'Database', 'CategoryModel', 'DiscussionModel', 'CommentModel');
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (isset($_POST['UserID'])){
|
||||
Gdn::Session()->Start($_POST['UserID'], TRUE, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
public function Index()
|
||||
{
|
||||
|
||||
$Limit = GetIncomingValue('limit', 5);
|
||||
$Offset = GetIncomingValue('offset', 0);
|
||||
$DiscussionID = GetIncomingValue('id', 0);
|
||||
|
@ -24,6 +34,7 @@ class DiscussionController extends APIController
|
|||
}
|
||||
|
||||
$this->Render();
|
||||
Gdn::Session()->End();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +44,7 @@ class DiscussionController extends APIController
|
|||
public function Add()
|
||||
{
|
||||
$Session = Gdn::Session();
|
||||
$Errors = array();
|
||||
$Errors = array();
|
||||
|
||||
// Set the model on the form.
|
||||
$this->Form->SetModel($this->DiscussionModel);
|
||||
|
@ -41,7 +52,6 @@ class DiscussionController extends APIController
|
|||
if($this->Form->AuthenticatedPostBack() === TRUE)
|
||||
{
|
||||
$FormValues = $this->Form->FormValues();
|
||||
|
||||
// Check category permissions
|
||||
if(!$Session->CheckPermission('Vanilla.Discussions.Add', $FormValues['CategoryID']))
|
||||
$Errors[] = 'You do not have permission to start discussions in this category';
|
||||
|
@ -57,6 +67,41 @@ class DiscussionController extends APIController
|
|||
$this->SetJSON("Errors", $Errors);
|
||||
|
||||
$this->Render();
|
||||
Gdn::Session()->End();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a discussion.
|
||||
* @param int The category id to add the discussion to.
|
||||
*/
|
||||
public function Remove()
|
||||
{
|
||||
$Session = Gdn::Session();
|
||||
$Errors = array();
|
||||
|
||||
// Set the model on the form.
|
||||
$this->Form->SetModel($this->DiscussionModel);
|
||||
|
||||
if($this->Form->AuthenticatedPostBack() === TRUE)
|
||||
{
|
||||
$FormValues = $this->Form->FormValues();
|
||||
|
||||
// Check category permissions
|
||||
if(!$Session->CheckPermission('Vanilla.Discussions.Add', $FormValues['CategoryID']))
|
||||
$Errors[] = 'You do not have permission to start discussions in this category';
|
||||
else
|
||||
$DiscussionID = $this->DiscussionModel->Delete($FormValues['DiscussionID']);
|
||||
$this->SetJSON("removed", $DiscussionID);
|
||||
}
|
||||
else
|
||||
$Errors[] = 'You do not have credentials to post as this user';
|
||||
|
||||
// Return the form errors
|
||||
if(count($Errors) > 0)
|
||||
$this->SetJSON("Errors", $Errors);
|
||||
|
||||
$this->Render();
|
||||
Gdn::Session()->End();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php if (!defined('APPLICATION')) exit();
|
||||
|
||||
class SessionAPIController extends APIController
|
||||
{
|
||||
|
||||
|
||||
public $Uses = array('Form', 'Database', 'CategoryModel', 'DiscussionModel', 'CommentModel','UserModel');
|
||||
//TODO should allow for only one catgories to be looked at
|
||||
public function Index()
|
||||
{
|
||||
|
||||
$Session = Gdn::Session();
|
||||
|
||||
if($Session->User != False)
|
||||
$this->SetJSON("user", array("TransientKey"=>$Session->TransientKey(), "UserID"=>$Session->UserID, "Name"=>$Session->User->Name, "User"=>True));
|
||||
else
|
||||
$this->SetJSON("user", array("TransientKey"=>$Session->TransientKey(), "UserID"=>0, "User"=>False));
|
||||
|
||||
$this->Render();
|
||||
}
|
||||
|
||||
|
||||
public function Login(){
|
||||
|
||||
$Username = GetIncomingValue('user', 'admin');
|
||||
$Password = GetIncomingValue('pass', 'pass');
|
||||
|
||||
$UserModel = new UserModel();
|
||||
$User = $UserModel->GetByEmail($Username);
|
||||
|
||||
if (!$User) {
|
||||
$User = $UserModel->GetByUsername($Username);
|
||||
}
|
||||
|
||||
$Result = FALSE;
|
||||
if ($User) {
|
||||
// Check the password.
|
||||
$PasswordHash = new Gdn_PasswordHash();
|
||||
$Result = $PasswordHash->CheckPassword($Password, val('Password', $User), val('HashMethod', $User));
|
||||
//print_r($User);exit;
|
||||
|
||||
if ($Result) {
|
||||
$Session = Gdn::Session();
|
||||
Gdn::Session()->Start($User->UserID, TRUE, TRUE);
|
||||
$this->SetJSON("user", array("TransientKey"=>$User->Attributes['TransientKey'], "UserID"=>$User->UserID, "Name"=>$User->Name, "User"=>$Result));
|
||||
} else {
|
||||
$this->SetJSON("user", array("TransientKey"=>false, "UserID"=>0, "User"=>False));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->Render();
|
||||
Gdn::Session()->End();
|
||||
|
||||
//echo ($Result) ? 'Success' : 'Failure';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,21 +0,0 @@
|
|||
<?php if (!defined('APPLICATION')) exit();
|
||||
|
||||
class SessionController extends APIController
|
||||
{
|
||||
//TODO should allow for only one catgories to be looked at
|
||||
public function Index()
|
||||
{
|
||||
|
||||
$Session = Gdn::Session();
|
||||
|
||||
if($Session->User != False)
|
||||
$this->SetJSON("user", array("TransientKey"=>$Session->TransientKey(), "UserID"=>$Session->UserID, "Name"=>$Session->User->Name, "User"=>True));
|
||||
else
|
||||
$this->SetJSON("user", array("TransientKey"=>$Session->TransientKey(), "UserID"=>0, "User"=>False));
|
||||
|
||||
$this->Render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue