mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
Move settings from smscontroller to dedicated controller
This commit is contained in:
parent
ccb13d3c31
commit
4827856fe2
@ -16,6 +16,7 @@ namespace OCA\OcSms\AppInfo;
|
|||||||
use \OCP\AppFramework\App;
|
use \OCP\AppFramework\App;
|
||||||
|
|
||||||
use \OCA\OcSms\Controller\ApiController;
|
use \OCA\OcSms\Controller\ApiController;
|
||||||
|
use \OCA\OcSms\Controller\SettingsController;
|
||||||
use \OCA\OcSms\Controller\SmsController;
|
use \OCA\OcSms\Controller\SmsController;
|
||||||
|
|
||||||
use \OCA\OcSms\Db\Sms;
|
use \OCA\OcSms\Db\Sms;
|
||||||
@ -72,6 +73,15 @@ class OcSmsApp extends App {
|
|||||||
/**
|
/**
|
||||||
* Controllers
|
* Controllers
|
||||||
*/
|
*/
|
||||||
|
$container->registerService('SettingsController', function($c) use($app) {
|
||||||
|
return new SettingsController(
|
||||||
|
$c->query('AppName'),
|
||||||
|
$c->query('Request'),
|
||||||
|
$c->query('ConfigMapper'),
|
||||||
|
$app
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
$container->registerService('SmsController', function($c) use($app) {
|
$container->registerService('SmsController', function($c) use($app) {
|
||||||
return new SmsController(
|
return new SmsController(
|
||||||
$c->query('AppName'),
|
$c->query('AppName'),
|
||||||
|
@ -20,9 +20,10 @@ $application->registerRoutes($this, array('routes' => array(
|
|||||||
array('name' => 'sms#delete_conversation', 'url' => '/delete/conversation', 'verb' => 'POST'),
|
array('name' => 'sms#delete_conversation', 'url' => '/delete/conversation', 'verb' => 'POST'),
|
||||||
array('name' => 'sms#check_new_messages', 'url' => '/get/new_messages', 'verb' => 'GET'),
|
array('name' => 'sms#check_new_messages', 'url' => '/get/new_messages', 'verb' => 'GET'),
|
||||||
array('name' => 'sms#delete_message', 'url' => '/delete/message', 'verb' => 'POST'),
|
array('name' => 'sms#delete_message', 'url' => '/delete/message', 'verb' => 'POST'),
|
||||||
array('name' => 'sms#set_country', 'url'=> '/set/country', 'verb' => 'POST'),
|
|
||||||
array('name' => 'sms#get_settings', 'url'=> '/get/settings', 'verb' => 'GET'),
|
array('name' => 'settings#set_country', 'url'=> '/set/country', 'verb' => 'POST'),
|
||||||
array('name' => 'sms#set_messagelimit', 'url'=> '/set/msglimit', 'verb' => 'POST'),
|
array('name' => 'settings#get_settings', 'url'=> '/get/settings', 'verb' => 'GET'),
|
||||||
|
array('name' => 'settings#set_messagelimit', 'url'=> '/set/msglimit', 'verb' => 'POST'),
|
||||||
|
|
||||||
array('name' => 'api#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), // Android APIv1
|
array('name' => 'api#get_api_version', 'url' => '/get/apiversion', 'verb' => 'GET'), // Android APIv1
|
||||||
array('name' => 'api#push', 'url' => '/push', 'verb' => 'POST'), // Android API
|
array('name' => 'api#push', 'url' => '/push', 'verb' => 'POST'), // Android API
|
||||||
|
70
controller/settingscontroller.php
Normal file
70
controller/settingscontroller.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?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-2016
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCA\OcSms\Controller;
|
||||||
|
|
||||||
|
|
||||||
|
use \OCP\IRequest;
|
||||||
|
use \OCP\AppFramework\Controller;
|
||||||
|
use \OCP\AppFramework\Http\JSONResponse;
|
||||||
|
use \OCP\AppFramework\Http;
|
||||||
|
|
||||||
|
use \OCA\OcSms\AppInfo\OcSmsApp;
|
||||||
|
|
||||||
|
use \OCA\OcSms\Db\ConfigMapper;
|
||||||
|
|
||||||
|
use \OCA\OcSms\Lib\CountryCodes;
|
||||||
|
|
||||||
|
class SettingsController extends Controller {
|
||||||
|
|
||||||
|
private $app;
|
||||||
|
private $configMapper;
|
||||||
|
|
||||||
|
public function __construct ($appName, IRequest $request, ConfigMapper $cfgMapper, OcSmsApp $app){
|
||||||
|
parent::__construct($appName, $request);
|
||||||
|
$this->app = $app;
|
||||||
|
$this->configMapper = $cfgMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*/
|
||||||
|
function setCountry($country) {
|
||||||
|
if (!array_key_exists($country, CountryCodes::$codes)) {
|
||||||
|
return new JSONResponse(array("status" => false, "msg" => "Invalid country"));
|
||||||
|
}
|
||||||
|
$this->configMapper->set("country", $country);
|
||||||
|
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*/
|
||||||
|
function getSettings() {
|
||||||
|
$country = $this->configMapper->getKey("country");
|
||||||
|
if ($country === false) {
|
||||||
|
return new JSONResponse(array("status" => false));
|
||||||
|
}
|
||||||
|
$message_limit = $this->configMapper->getKey("message_limit");
|
||||||
|
return new JSONResponse(array("status" => true,
|
||||||
|
"country" => $country,
|
||||||
|
"message_limit" => $message_limit));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*/
|
||||||
|
function setMessageLimit($limit) {
|
||||||
|
$this->configMapper->set("message_limit", $limit);
|
||||||
|
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -227,38 +227,4 @@ class SmsController extends Controller {
|
|||||||
$this->smsMapper->removeMessage($this->userId, $phoneNumber, $messageId);
|
$this->smsMapper->removeMessage($this->userId, $phoneNumber, $messageId);
|
||||||
return new JSONResponse(array());
|
return new JSONResponse(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
function setCountry($country) {
|
|
||||||
if (!array_key_exists($country, CountryCodes::$codes)) {
|
|
||||||
return new JSONResponse(array("status" => false, "msg" => "Invalid country"));
|
|
||||||
}
|
|
||||||
$this->configMapper->set("country", $country);
|
|
||||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
function getSettings() {
|
|
||||||
$country = $this->configMapper->getKey("country");
|
|
||||||
if ($country === false) {
|
|
||||||
return new JSONResponse(array("status" => false));
|
|
||||||
}
|
|
||||||
$message_limit = $this->configMapper->getKey("message_limit");
|
|
||||||
return new JSONResponse(array("status" => true,
|
|
||||||
"country" => $country,
|
|
||||||
"message_limit" => $message_limit));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @NoAdminRequired
|
|
||||||
*/
|
|
||||||
function setMessageLimit($limit) {
|
|
||||||
$this->configMapper->set("message_limit", $limit);
|
|
||||||
return new JSONResponse(array("status" => true, "msg" => "OK"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user