1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 16:06:15 +00:00

Create a basic SmsController

This commit is contained in:
Loïc Blot (@U-Exp) 2014-09-12 13:59:19 +02:00
parent 8d03780e6f
commit 3ad96daa21
4 changed files with 42 additions and 65 deletions

View File

@ -14,7 +14,7 @@ namespace OCA\OcSms\AppInfo;
use \OCP\AppFramework\App; use \OCP\AppFramework\App;
use \OCA\OcSms\Controller\PageController; use \OCA\OcSms\Controller\SmsController;
class Application extends App { class Application extends App {
@ -28,9 +28,10 @@ class Application extends App {
/** /**
* Controllers * Controllers
*/ */
$container->registerService('PageController', function($c) {
return new PageController( $container->registerService('SmsController', function($c) {
$c->query('AppName'), return new SmsController(
$c->query('AppName'),
$c->query('Request'), $c->query('Request'),
$c->query('UserId') $c->query('UserId')
); );
@ -42,9 +43,7 @@ class Application extends App {
*/ */
$container->registerService('UserId', function($c) { $container->registerService('UserId', function($c) {
return \OCP\User::getUser(); return \OCP\User::getUser();
}); });
} }
}
}

View File

@ -22,6 +22,5 @@ namespace OCA\OcSms\AppInfo;
$application = new Application(); $application = new Application();
$application->registerRoutes($this, array('routes' => array( $application->registerRoutes($this, array('routes' => array(
array('name' => 'page#index', 'url' => '/', 'verb' => 'GET'), array('name' => 'sms#push', 'url' => '/push', 'verb' => 'POST'),
array('name' => 'page#do_echo', 'url' => '/echo', 'verb' => 'POST'),
))); )));

View File

@ -1,54 +0,0 @@
<?php
/**
* ownCloud - ocsms
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @copyright Loic Blot 2014
*/
namespace OCA\OcSms\Controller;
use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
class PageController extends Controller {
private $userId;
public function __construct($appName, IRequest $request, $userId){
parent::__construct($appName, $request);
$this->userId = $userId;
}
/**
* CAUTION: the @Stuff turn off security checks, for this page no admin is
* required and no CSRF check. If you don't know what CSRF is, read
* it up in the docs or you might create a security hole. This is
* basically the only required method to add this exemption, don't
* add it to any other method if you don't exactly know what it does
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index() {
$params = array('user' => $this->userId);
return new TemplateResponse('ocsms', 'main', $params); // templates/main.php
}
/**
* Simply method that posts back the payload of the request
* @NoAdminRequired
*/
public function doEcho($echo) {
return array('echo' => $echo);
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* ownCloud - ocsms
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @copyright Loic Blot 2014
*/
namespace OCA\OcSms\Controller;
use \OCP\IRequest;
use \OCP\AppFramework\Http\TemplateResponse;
use \OCP\AppFramework\Controller;
class SmsController extends Controller {
private $userId;
public function __construct($appName, IRequest $request, $userId){
parent::__construct($appName, $request);
$this->userId = $userId;
}
public function push() {
return array("test" => "test2");
}
}