Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 356505c

Browse files
committed
ENH: refs #237. Test: change password changes default API key
1 parent 705973f commit 356505c

File tree

9 files changed

+364
-293
lines changed

9 files changed

+364
-293
lines changed

modules/api/controllers/ConfigController.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
<?php
22

3+
/** api config controller */
34
class Api_ConfigController extends Api_AppController
45
{
5-
public $_moduleForms=array('Config');
6-
public $_components=array('Utility', 'Date');
7-
public $_moduleModels=array('Userapi');
6+
public $_moduleForms = array('Config');
7+
public $_components = array('Utility', 'Date');
8+
public $_moduleModels = array('Userapi');
9+
10+
/** user config*/
11+
function usertabAction()
12+
{
13+
$this->_helper->layout->disableLayout();
14+
if(!$this->logged)
15+
{
16+
throw new Zend_Exception('Please Log in');
17+
}
818

9-
/** user config*/
10-
function usertabAction()
11-
{
12-
$this->_helper->layout->disableLayout();
13-
if(!$this->logged)
14-
{
15-
throw new Zend_Exception('Please Log in');
16-
}
17-
1819
$this->view->Date = $this->Component->Date;
1920

2021
$form = $this->ModuleForm->Config->createKeyForm();
@@ -29,7 +30,7 @@ function usertabAction()
2930
$this->_helper->viewRenderer->setNoRender();
3031
$applicationName = $this->_getParam('appplication_name');
3132
$tokenExperiationTime = $this->_getParam('expiration');
32-
$userapiDao = $this->Api_Userapi->createKey($this->userSession->Dao,$applicationName,$tokenExperiationTime);
33+
$userapiDao = $this->Api_Userapi->createKey($this->userSession->Dao, $applicationName, $tokenExperiationTime);
3334
if($userapiDao != false)
3435
{
3536
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
@@ -45,7 +46,7 @@ function usertabAction()
4546
$element = $this->_getParam('element');
4647
$userapiDao = $this->Api_Userapi->load($element);
4748
// Make sure the key belongs to the user
48-
if($userapiDao !=false && ($userapiDao->getUserId() == $this->userSession->Dao->getKey() ||$this->userSession->Dao->isAdmin()))
49+
if($userapiDao != false && ($userapiDao->getUserId() == $this->userSession->Dao->getKey() || $this->userSession->Dao->isAdmin()))
4950
{
5051
$this->Api_Userapi->delete($userapiDao);
5152
echo JsonComponent::encode(array(true, $this->t('Changes saved')));
@@ -61,15 +62,15 @@ function usertabAction()
6162
$userapiDaos = $this->Api_Userapi->getByUser($this->userSession->Dao);
6263
$this->view->userapiDaos = $userapiDaos;
6364
}
64-
65-
/** index action*/
66-
function indexAction()
65+
66+
/** index action*/
67+
function indexAction()
6768
{
68-
if(!$this->logged||!$this->userSession->Dao->getAdmin()==1)
69+
if(!$this->logged || !$this->userSession->Dao->getAdmin() == 1)
6970
{
7071
throw new Zend_Exception("You should be an administrator");
7172
}
72-
73+
7374
if(file_exists(BASE_PATH."/core/configs/api.local.ini"))
7475
{
7576
$applicationConfig = parse_ini_file(BASE_PATH."/core/configs/api.local.ini", true);
@@ -79,12 +80,12 @@ function indexAction()
7980
$applicationConfig = parse_ini_file(BASE_PATH.'/modules/api/configs/module.ini', true);
8081
}
8182
$configForm = $this->ModuleForm->Config->createConfigForm();
82-
83-
$formArray = $this->getFormAsArray($configForm);
83+
84+
$formArray = $this->getFormAsArray($configForm);
8485
$formArray['methodprefix']->setValue($applicationConfig['global']['methodprefix']);
85-
86+
8687
$this->view->configForm = $formArray;
87-
88+
8889
if($this->_request->isPost())
8990
{
9091
$this->_helper->layout->disableLayout();
@@ -98,13 +99,13 @@ function indexAction()
9899
}
99100
if(file_exists(BASE_PATH."/core/configs/api.local.ini"))
100101
{
101-
rename(BASE_PATH."/core/configs/api.local.ini",BASE_PATH."/core/configs/api.local.ini.old");
102+
rename(BASE_PATH."/core/configs/api.local.ini", BASE_PATH."/core/configs/api.local.ini.old");
102103
}
103104
$applicationConfig['global']['methodprefix'] = $this->_getParam('methodprefix');
104105
$this->Component->Utility->createInitFile(BASE_PATH."/core/configs/api.local.ini", $applicationConfig);
105106
echo JsonComponent::encode(array(true, 'Changed saved'));
106107
}
107108
}
108-
}
109-
109+
}
110+
110111
}//end class

0 commit comments

Comments
 (0)