Blame | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** UserAccounts Controller** @property UserAccount $UserAccount* @property PaginatorComponent $Paginator*/class UserAccountsController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function beforeFilter() {parent::beforeFilter();$this->Auth->allow('saholic');$this->apihost = Configure::read('pythonapihost');}public function saholic($userId=null){$this->response->type('json');$this->layout = 'ajax';if(!$userId){$result = array('success'=>false,'message'=>'UserId is missing','account_key'=>-1);}else{$options = array('conditions'=>array('user_id'=>$userId,'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');$userAccount = $this->UserAccount->find('first',$options);if(empty($userAccount)){$result = array('success'=>false,'message'=>'UserId not present in our system','account_key'=>-1);}else{$result = array('success'=>true,'message'=>'UserId present in our system','account_key'=>$userAccount['UserAccount']['account_key']);}}$this->set(array('result' => $result,// 'callback' => $callback,'_serialize' => array('result')));$this->render('/Elements/json');}/*** index method** @return void*/public function index() {$this->UserAccount->recursive = 0;$this->set('userAccounts', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {if (!$this->UserAccount->exists($id)) {throw new NotFoundException(__('Invalid user account'));}$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));$this->set('userAccount', $this->UserAccount->find('first', $options));}/*** add method** @return void*/public function add() {if ($this->request->is('post')) {$this->UserAccount->create();if ($this->UserAccount->save($this->request->data)) {$this->Session->setFlash(__('The user account has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));}}$users = $this->UserAccount->User->find('list');$this->set(compact('users'));}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->UserAccount->exists($id)) {throw new NotFoundException(__('Invalid user account'));}if ($this->request->is(array('post', 'put'))) {if ($this->UserAccount->save($this->request->data)) {$this->Session->setFlash(__('The user account has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));$this->request->data = $this->UserAccount->find('first', $options);}$users = $this->UserAccount->User->find('list');$this->set(compact('users'));}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->UserAccount->id = $id;if (!$this->UserAccount->exists()) {throw new NotFoundException(__('Invalid user account'));}$this->request->onlyAllow('post', 'delete');if ($this->UserAccount->delete()) {$this->Session->setFlash(__('The user account has been deleted.'));} else {$this->Session->setFlash(__('The user account could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$this->UserAccount->recursive = 0;$this->set('userAccounts', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->UserAccount->exists($id)) {throw new NotFoundException(__('Invalid user account'));}$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));$this->set('userAccount', $this->UserAccount->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {$this->UserAccount->create();if ($this->UserAccount->save($this->request->data)) {$this->Session->setFlash(__('The user account has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));}}$users = $this->UserAccount->User->find('list');$this->set(compact('users'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->UserAccount->exists($id)) {throw new NotFoundException(__('Invalid user account'));}if ($this->request->is(array('post', 'put'))) {if ($this->UserAccount->save($this->request->data)) {$this->Session->setFlash(__('The user account has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The user account could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('UserAccount.' . $this->UserAccount->primaryKey => $id));$this->request->data = $this->UserAccount->find('first', $options);}$users = $this->UserAccount->User->find('list');$this->set(compact('users'));}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->UserAccount->id = $id;if (!$this->UserAccount->exists()) {throw new NotFoundException(__('Invalid user account'));}$this->request->onlyAllow('post', 'delete');if ($this->UserAccount->delete()) {$this->Session->setFlash(__('The user account has been deleted.'));} else {$this->Session->setFlash(__('The user account could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}}