Rev 15070 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Agents Controller** @property Agent $Agent* @property PaginatorComponent $Paginator*/class AgentsController extends AppController {/*** Components** @var array*/public $components = array('Paginator');public function beforeFilter() {parent::beforeFilter();$this->Auth->allow(array('authenticate'));}/*** index method** @return void*/public function index() {$this->Agent->recursive = 0;$this->set('agents', $this->Paginator->paginate());}/*** view method** @throws NotFoundException* @param string $id* @return void*/public function view($id = null) {if (!$this->Agent->exists($id)) {throw new NotFoundException(__('Invalid agent'));}$options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));$this->set('agent', $this->Agent->find('first', $options));}/*** add method** @return void*/public function add() {if ($this->request->is('post')) {$this->Agent->create();if ($this->Agent->save($this->request->data)) {$this->Session->setFlash(__('The agent has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The agent could not be saved. Please, try again.'));}}}/*** edit method** @throws NotFoundException* @param string $id* @return void*/public function edit($id = null) {if (!$this->Agent->exists($id)) {throw new NotFoundException(__('Invalid agent'));}if ($this->request->is(array('post', 'put'))) {if ($this->Agent->save($this->request->data)) {$this->Session->setFlash(__('The agent has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The agent could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));$this->request->data = $this->Agent->find('first', $options);}}/*** delete method** @throws NotFoundException* @param string $id* @return void*/public function delete($id = null) {$this->Agent->id = $id;if (!$this->Agent->exists()) {throw new NotFoundException(__('Invalid agent'));}$this->request->onlyAllow('post', 'delete');if ($this->Agent->delete()) {$this->Session->setFlash(__('The agent has been deleted.'));} else {$this->Session->setFlash(__('The agent could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}/*** admin_index method** @return void*/public function admin_index() {$this->Agent->recursive = 0;$this->set('agents', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->Agent->exists($id)) {throw new NotFoundException(__('Invalid agent'));}$options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));$this->set('agent', $this->Agent->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {$this->Agent->create();if ($this->Agent->save($this->request->data)) {$this->Session->setFlash(__('The agent has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The agent could not be saved. Please, try again.'));}}}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->Agent->exists($id)) {throw new NotFoundException(__('Invalid agent'));}if ($this->request->is(array('post', 'put'))) {if ($this->Agent->save($this->request->data)) {$this->Session->setFlash(__('The agent has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The agent could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Agent.' . $this->Agent->primaryKey => $id));$this->request->data = $this->Agent->find('first', $options);}}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->Agent->id = $id;if (!$this->Agent->exists()) {throw new NotFoundException(__('Invalid agent'));}$this->request->onlyAllow('post', 'delete');if ($this->Agent->delete()) {$this->Session->setFlash(__('The agent has been deleted.'));} else {$this->Session->setFlash(__('The agent could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}public function authenticate(){$this->log(print_r($this->request->data,1),'authenticatication');if (!$this->Agent->exists($email)) {$result = array('success'=>false,'message'=>'Invalid user1');}else{$agentEmail = $this->request->data['email'];$agentPassword = $this->request->data['password'];$agentRole = $this->request->data['role'];$conditions = array('email'=>$agentEmail,'password'=>$agentPassword);$fields = array('id');$agentExists = $this->Agent->find('first',array('conditions'=>$conditions,'fields'=>$fields));if(empty($agentExists)){$result = array('success'=>false,'message'=>'Invalid Role');}else{$this->loadModel('Agent_Role');$options = array('conditions' => array('id'=> $agentId,'status'=>$agentRole));$count = $this->AgentRole->find('count',$options);if(!$count){$result = array('success'=>false,'message'=>'Invalid Role');}else{$result = array('success'=>true,'message'=>'Valid User');}}}$this->set(array('result' => $result,'_serialize' => array('result')));$this->render('/Elements/json');}}