Server IP : 180.180.241.3 / Your IP : 216.73.216.194 Web Server : Microsoft-IIS/7.5 System : Windows NT NETWORK-NHRC 6.1 build 7601 (Windows Server 2008 R2 Standard Edition Service Pack 1) i586 User : IUSR ( 0) PHP Version : 5.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/AppServ/www/app/Controller/ |
Upload File : |
<?php App::uses('AppController', 'Controller'); App::uses('File', 'Utility'); App::uses('CakeEmail', 'Network/Email'); /** * Users Controller * * @property User $User * @property PaginatorComponent $Paginator */ class UsersController extends AppController { /** * Components * * @var array */ public $components = array('Paginator'); public $layout = 'admin'; public function beforeFilter() { parent::beforeFilter(); // For CakePHP 2.1 and up // $this->Auth->allow(); $this->Auth->allow( array( 'initDB', 'forgotPassword', 'resetPassword' ) ); // $this->Auth->deny( 'admin_dashboard' ); } /** * Login to admin panel. * * @return void return to same page if login fail. * @author 3Musketeers <3musketeersteam@gmail.com> * @since 14 September 2013 */ public function login() { // the user is already logged in if ($this->Session->read('Auth.User')) { $this->Session->setFlash(__('คุณล็อกอินอยู่ในระบบแล้ว'), 'flash-info'); return $this->redirect('/'); } // the user submits login information if ($this->request->is('post')) { if ( $this->Auth->login() ) { //`redirect_url` is in `group` table. return $this->redirect($this->Auth->user('Group.redirect_url')); } $this->Session->setFlash(__('ชื่อเข้าระบบ หรือรหัสผ่านผิดพลาด'), 'flash-fail'); } $this->layout = 'login'; $this->set('topicTitle', __('เข้าสู่ระบบ')); } public function logout() { //Leave empty for now. // $this->Session->setFlash(__('ออกจากระบบ'), 'flash-info'); $this->redirect($this->Auth->logout()); } /** * index method * * @return void */ public function admin_index() { $conditions = array(); $username = ''; $groupId = ''; $date = ''; $dateTo = ''; if ( isset($this->params->query['username']) ) { $username = $this->params->query['username']; $conditions['AND']['User.username LIKE'] = '%' . $username . '%'; } //Set status for query if ( !isset($this->params->query['status']) ) { $this->params->query['status'] = 1; } // must select both start and end dates if ( isset($this->params->query['date']) && !empty($this->params->query['date']) && isset($this->params->query['date_to']) && !empty($this->params->query['date_to']) ) { $date = $this->params->query['date']; $dateTo = $this->params->query['date_to']; $conditions['AND']['User.created BETWEEN ? AND ?'] = array($date . ' 00:00:00', $dateTo . ' 23:59:59'); } if ( isset($this->params->query['group_id']) && !empty($this->params->query['group_id']) ) { $groupId = $this->params->query['group_id']; $conditions['AND']['User.group_id'] = $groupId; } $conditions['User.is_activated'] = array($this->params->query['status']); $this->Paginator->settings['conditions'] = $conditions; $this->User->recursive = 0; $this->set('users', $this->Paginator->paginate()); //Find all group to use in filter form. $this->set('groups', $this->User->Group->find('list')); $this->set('topicTitle', 'ผู้ใช้งาน'); $this->set('username', $username); $this->set('group_id', $groupId); $this->set('date', $date); $this->set('date_to', $dateTo); } /** * Landing page for administrator and editor after login. * * @author 3Muketeers <3musketeersteam@gmail.com> * @since 14 September 2013 */ public function admin_dashboard() { if ( $this->Session->read('Auth.User.group_id') == '3' ) { $this->redirect( array( 'controller' => 'pages', 'action' => 'index', 'admin' => false ) ); } //Find organization and Pepole $this->loadModel('Organization'); $this->loadModel('Person'); $conditions = array( 'limit' => '10', 'recursive' => -1, //@TODO : Is the same if we order by `id` and `created` in `DESC`? //Because we need the lasted to show first. 'order' => array('id' => 'DESC') ); $organizations = $this->Organization->find('all', $conditions); $people = $this->Person->find('all', $conditions); $this->set(compact('organizations', 'people')); $this->set('all_organizations', $this->Organization->find('count')); $this->set('all_people', $this->Person->find('count')); $this->set('topicTitle', __('Dashboard')); } /** * view method * * @throws NotFoundException * @param string $id * @return void */ public function admin_view($id = null) { if (!$this->User->exists($id)) { throw new NotFoundException(__('Invalid user')); } $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); $this->set('user', $this->User->find('first', $options)); } /** * add method * * @return void */ public function admin_add() { if ($this->request->is('post')) { $this->User->create(); if ($this->User->save($this->request->data)) { $this->Session->setFlash(__('The user has been saved.'), 'flash-success'); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The user could not be saved. Please, try again.'), 'flash-fail'); } } $groups = $this->User->Group->find('list'); $this->set(compact('groups')); $this->set( 'topicTitle', __( 'เพิ่มผู้ใช้งาน' ) ); } /** * edit method * * @throws NotFoundException * @param string $id * @return void */ public function admin_edit($id = null) { if (!$this->User->exists($id)) { throw new NotFoundException(__('Invalid user')); } if ($this->request->is('post') || $this->request->is('put')) { // debug($this->request->data); exit(); $this->User->id = $id; $validateFields = array( 'username', 'email', 'group_id' ); if( !empty( $this->request->data['User']['password'] ) ) { $validateFields[] = 'password'; } if ( $this->User->save( $this->request->data, true, $validateFields ) ) { $this->Session->setFlash(__('บันทึกข้อมูลสำเร็จ'), 'flash-success'); return $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('ไม่สามารถบันทึกขอมูลได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); } } else { $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); $this->request->data = $this->User->find('first', $options); } $groups = $this->User->Group->find('list'); $this->set(compact('groups')); $this->set( 'topicTitle', __( 'แก้ไขข้อมูลผู้ใช้' ) ); } /** * admin_delete method * * @throws NotFoundException * @param string $id * @return void */ public function admin_delete($id = null) { $this->User->id = $id; if (!$this->User->exists()) { throw new NotFoundException(__('Invalid User')); } $this->request->onlyAllow('get', 'delete', 'post'); if ($this->User->delete()) { $this->Session->setFlash(__('ลบผู้ใช้งานเรียบร้อยแล้ว'), 'flash-success'); } else { $this->Session->setFlash(__('ไม่สามารถลบผู้ใช้งานได้'), 'flash-fail'); } return $this->redirect(array('action' => 'index')); } /** * [edit description] * @param [type] $id [description] * @return [type] [description] */ public function edit() { $id = $this->Auth->user( 'id' ); if (!$this->User->exists($id)) { throw new NotFoundException(__('Invalid user')); } if ($this->request->is('post') || $this->request->is('put')) { $this->User->id = $id; if ( $this->User->save( $this->request->data, true, array( 'password' ) ) ) { $this->Session->setFlash(__('รหัสผ่านของคุณถูกเปลี่ยนแล้ว.'), 'flash-success'); } else { $this->Session->setFlash(__('ไม่สามารถเปลี่ยนรหัสผ่านได้'), 'flash-fail'); } } $this->set( 'topicTitle', __( 'เปลี่ยนรหัสผ่าน' ) ); } /** * activate items from inactivated. * * @param int $id activity's id * @author Ting <3Musketeersteam@gmail.com> * @since 27 January 2014 */ public function admin_active($id = null) { $this->User->id = $id; if (!$this->User->exists()) { throw new NotFoundException(__('ไม่พบข้อผู้ใช้งาน')); } $this->request->onlyAllow('get', 'delete', 'post'); if ($this->User->activate()) { $this->Session->setFlash(__('เปิดใช้งานผู้ใช้งานเรียบร้อยแล้ว'), 'flash-success'); } else { $this->Session->setFlash(__('ไม่สามารถเปิดการใช้งานผู้ใช้งาน'), 'flash-fail'); } return $this->redirect(array('action' => 'index')); } public function forgotPassword() { $this->layout = 'login'; if ( $this->request->is('post') ) { // If the data posted doesn't contain the email address, there is a problem... if ( empty($this->request->data['email']) ) { throw new BadRequestException(); } // Is there a user account linked to the given email address ? $email = $this->request->data['email']; $options = array( 'conditions' => array( 'User.email' => $email), // 'User.active' => '1', // 'User.role' => 'user'), 'recursive' => -1 ); $user = $this->User->find('first', $options); if ( empty( $user ) ) { // No user found $this->layout = 'login'; $this->Session->setFlash( __('ไม่พบผู้ใช้งานที่ใช้อีเมล์นี้'), 'flash-fail'); return; } // Create a new activation code $user['User']['activation'] = $this->getActivationHash(); $this->User->id = $user['User']['id']; if ( !$this->User->save($user['User']) ) { $this->Session->setFlash( __('มีบางสิ่งผิดพลาดไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้ง'), 'flash-fail'); return; } // Send the email to the user $this->sendLostPasswordEmail($user); $this->set( 'topicTitle', __( 'ส่งอีเมล์สำเร็จ' ) ); $this->render('send_success'); // $this->Session->setFlash('Email sent. Please check your inbox and follow the link in the email.', 'flash-success'); } $this->set( 'topicTitle', __( 'ลืมรหัสผ่าน' ) ); } private function getActivationHash() { $fullHash = Security::hash(Configure::read('Security.salt') . time() . date('Ymd')); return $fullHash; } /** * This function is used to send an password reset email to a user * @param type $user information about the user * @modify 2012-11-28 - Mike - Use a component to send email */ private function sendLostPasswordEmail( $user ) { $Email = new CakeEmail(); $Email->config('gmail'); $Email->template('forgot_password') ->emailFormat('html') ->from( array('info@nhrc.or.th' => __('สำนักงานคณะกรรมการสิทธิมนุษยชนแห่งชาติ') )) ->to($user['User']['email']) ->subject( __('กู้คืนรหัสผ่านของคุณ') ) ->viewVars($user['User']) ->send(); } /** * * @param type $userEmail the email we want to use to retrieve the account information * @param type $activationHash the hash code to make the URL unique * @modify 2012-11-30 - Mike - The account does not need to be active to retrieve the password */ public function resetPassword( $userEmail = null, $activationHash = null ) { $this->layout = 'login'; $options = array( 'conditions' => array( 'User.email' => $userEmail, 'User.activation' => $activationHash), // 'User.active' => '1', // 'User.role' => 'user'), 'recursive' => -1 ); $user = $this->User->find('first', $options); if ( empty($user) ) { $this->layout = 'login'; $this->set( 'topicTitle', __( 'ไม่พบข้อมูล กรุณาลองใหม่อีกครั้ง' ) ); $this->render('resetpassword-error'); return; } $this->User->id = $user['User']['id']; if ( $this->request->is('post') || $this->request->is('put') ) { $this->User->Behaviors->attach('Passwordable', array('allowEmpty' => true,)); $this->request->data['User']['activation'] = ''; if ( !$this->User->save($this->request->data) ) { $this->layout = 'login'; $this->set( 'topicTitle', __( 'เกิดข้อิดพลาด กรุณาลองใหม่อีกครั้ง' ) ); $this->render('resetpassword-error'); return; } $this->set( 'topicTitle', __( 'เปลี่ยนรหัสผ่านสำเร็จแล้ว' ) ); $this->render('resetpassword-ok'); return; } $this->set( 'topicTitle', __( 'ตั้งรหัสผ่านใหม่' ) ); } public function initDB() { $group = $this->User->Group; // Allow admins to everything // `index` action is not included here because we will set // in appcontroller's beforeFilter() to allow for non-registered users $group->id = 1; $this->Acl->allow($group, 'controllers'); // editors $group->id = 2; $this->Acl->deny($group, 'controllers'); $this->Acl->allow($group, 'controllers/Users/login'); $this->Acl->allow($group, 'controllers/Users/admin_dashboard'); $this->Acl->allow($group, 'controllers/Users/logout'); $this->Acl->allow($group, 'controllers/Users/edit'); // organizations $this->Acl->allow($group, 'controllers/Organizations/admin_index'); $this->Acl->allow($group, 'controllers/Organizations/admin_view'); $this->Acl->allow($group, 'controllers/Organizations/admin_add'); $this->Acl->allow($group, 'controllers/Organizations/admin_edit'); $this->Acl->allow($group, 'controllers/Organizations/admin_delete'); $this->Acl->allow($group, 'controllers/Organizations/admin_active'); $this->Acl->allow($group, 'controllers/Organizations/admin_mouDelete'); $this->Acl->allow($group, 'controllers/Organizations/index'); $this->Acl->allow($group, 'controllers/Organizations/index_mou'); $this->Acl->allow($group, 'controllers/Organizations/view'); $this->Acl->allow($group, 'controllers/Organizations/admin_export'); // foreign organizations $this->Acl->allow($group, 'controllers/ForeignOrganizations/index'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/view'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/admin_index'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/admin_add'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/admin_edit'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/admin_delete'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/admin_active'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/admin_export'); // people $this->Acl->allow($group, 'controllers/People/admin_index'); $this->Acl->allow($group, 'controllers/People/admin_view'); $this->Acl->allow($group, 'controllers/People/admin_add'); $this->Acl->allow($group, 'controllers/People/admin_edit'); $this->Acl->allow($group, 'controllers/People/admin_delete'); $this->Acl->allow($group, 'controllers/People/admin_active'); $this->Acl->allow($group, 'controllers/People/admin_memberDelete'); $this->Acl->allow($group, 'controllers/People/index'); $this->Acl->allow($group, 'controllers/People/index_member'); $this->Acl->allow($group, 'controllers/People/view'); $this->Acl->allow($group, 'controllers/People/admin_export'); // topic // $this->Acl->allow($group, 'controllers/Topics/admin_index'); // $this->Acl->allow($group, 'controllers/Topics/admin_add'); // $this->Acl->allow($group, 'controllers/Topics/admin_edit'); // $this->Acl->allow($group, 'controllers/Topics/admin_delete'); // $this->Acl->allow($group, 'controllers/Topics/admin_export'); // subtopics // $this->Acl->allow($group, 'controllers/Subtopics/admin_index'); // $this->Acl->allow($group, 'controllers/Subtopics/admin_view'); // $this->Acl->allow($group, 'controllers/Subtopics/admin_add'); // $this->Acl->allow($group, 'controllers/Subtopics/admin_edit'); // $this->Acl->allow($group, 'controllers/Subtopics/admin_delete'); // $this->Acl->allow($group, 'controllers/Subtopics/get'); // $this->Acl->allow($group, 'controllers/Subtopics/admin_export'); // activities $this->Acl->allow($group, 'controllers/Activities/admin_index'); $this->Acl->allow($group, 'controllers/Activities/admin_view'); $this->Acl->allow($group, 'controllers/Activities/admin_add'); $this->Acl->allow($group, 'controllers/Activities/admin_edit'); $this->Acl->allow($group, 'controllers/Activities/admin_delete'); $this->Acl->allow($group, 'controllers/Activities/admin_active'); $this->Acl->allow($group, 'controllers/Activities/admin_add_photo'); $this->Acl->allow($group, 'controllers/Activities/index'); $this->Acl->allow($group, 'controllers/Activities/index_member'); $this->Acl->allow($group, 'controllers/Activities/view'); $this->Acl->allow($group, 'controllers/Activities/getVisitors'); $this->Acl->allow($group, 'controllers/Activities/admin_export'); // types // $this->Acl->allow($group, 'controllers/Types/admin_index'); // $this->Acl->allow($group, 'controllers/Types/admin_add'); // $this->Acl->allow($group, 'controllers/Types/admin_edit'); // $this->Acl->allow($group, 'controllers/Types/admin_delete'); // $this->Acl->allow($group, 'controllers/Types/admin_export'); // Positions // $this->Acl->allow($group, 'controllers/Positions/admin_index'); // $this->Acl->allow($group, 'controllers/Positions/admin_add'); // $this->Acl->allow($group, 'controllers/Positions/admin_edit'); // $this->Acl->allow($group, 'controllers/Positions/admin_delete'); // $this->Acl->allow($group, 'controllers/Positions/admin_export'); // Actions // $this->Acl->allow($group, 'controllers/Actions/admin_index'); // $this->Acl->allow($group, 'controllers/Actions/admin_add'); // $this->Acl->allow($group, 'controllers/Actions/admin_view'); // $this->Acl->allow($group, 'controllers/Actions/admin_edit'); // $this->Acl->allow($group, 'controllers/Actions/admin_delete'); // $this->Acl->allow($group, 'controllers/Actions/admin_export'); // Chiefs $this->Acl->allow($group, 'controllers/Chiefs/admin_index'); $this->Acl->allow($group, 'controllers/Chiefs/admin_add'); $this->Acl->allow($group, 'controllers/Chiefs/admin_edit'); $this->Acl->allow($group, 'controllers/Chiefs/admin_delete'); $this->Acl->allow($group, 'controllers/Chiefs/admin_export'); // Contacts $this->Acl->allow($group, 'controllers/Contacts/admin_index'); $this->Acl->allow($group, 'controllers/Contacts/admin_add'); $this->Acl->allow($group, 'controllers/Contacts/admin_view'); $this->Acl->allow($group, 'controllers/Contacts/admin_edit'); $this->Acl->allow($group, 'controllers/Contacts/admin_delete'); $this->Acl->allow($group, 'controllers/Contacts/admin_export'); // Roles // $this->Acl->allow($group, 'controllers/Roles/admin_index'); // $this->Acl->allow($group, 'controllers/Roles/admin_add'); // $this->Acl->allow($group, 'controllers/Roles/admin_edit'); // $this->Acl->allow($group, 'controllers/Roles/admin_delete'); // $this->Acl->allow($group, 'controllers/Roles/admin_export'); // Froles // $this->Acl->allow($group, 'controllers/Froles/admin_index'); // $this->Acl->allow($group, 'controllers/Froles/admin_add'); // $this->Acl->allow($group, 'controllers/Froles/admin_edit'); // $this->Acl->allow($group, 'controllers/Froles/admin_delete'); // $this->Acl->allow($group, 'controllers/Froles/admin_export'); // Targets // $this->Acl->allow($group, 'controllers/Targets/admin_index'); // $this->Acl->allow($group, 'controllers/Targets/admin_add'); // $this->Acl->allow($group, 'controllers/Targets/admin_edit'); // $this->Acl->allow($group, 'controllers/Targets/admin_delete'); // $this->Acl->allow($group, 'controllers/Targets/admin_export'); // Offers // $this->Acl->allow($group, 'controllers/Offers/admin_index'); // $this->Acl->allow($group, 'controllers/Offers/admin_add'); // $this->Acl->allow($group, 'controllers/Offers/admin_edit'); // $this->Acl->allow($group, 'controllers/Offers/admin_delete'); // $this->Acl->allow($group, 'controllers/Offers/admin_export'); // Members // $this->Acl->allow($group, 'controllers/Members/admin_index'); // $this->Acl->allow($group, 'controllers/Members/admin_add'); // $this->Acl->allow($group, 'controllers/Members/admin_edit'); // $this->Acl->allow($group, 'controllers/Members/admin_delete'); // $this->Acl->allow($group, 'controllers/Members/admin_view'); // $this->Acl->allow($group, 'controllers/Members/admin_export'); // pages $this->Acl->allow($group, 'controllers/Pages/peopleMapThailand'); $this->Acl->allow($group, 'controllers/Pages/regions'); $this->Acl->allow($group, 'controllers/Pages/peopleMapRegions'); $this->Acl->allow($group, 'controllers/Pages/peopleMapProvinces'); $this->Acl->allow($group, 'controllers/Pages/provinces'); $this->Acl->allow($group, 'controllers/Pages/set_provinces_slugs'); $this->Acl->allow($group, 'controllers/Pages/error404'); $this->Acl->allow($group, 'controllers/Pages/admin_error404'); $this->Acl->allow($group, 'controllers/Pages/chartCountry'); $this->Acl->allow($group, 'controllers/Pages/chartPeopleCountry'); $this->Acl->allow($group, 'controllers/Pages/chartRegion'); $this->Acl->allow($group, 'controllers/Pages/chartPeopleRegion'); $this->Acl->allow($group, 'controllers/Pages/chartPeopleProvince'); $this->Acl->allow($group, 'controllers/Pages/chartProvince'); $this->Acl->allow($group, 'controllers/Pages/reports'); $this->Acl->allow($group, 'controllers/Pages/reports_organizations'); $this->Acl->allow($group, 'controllers/Pages/reports_people'); $this->Acl->allow($group, 'controllers/Pages/reports_activities'); $this->Acl->allow($group, 'controllers/Pages/allinfo_reports_organizations'); $this->Acl->allow($group, 'controllers/Pages/allinfo_reports_people'); $this->Acl->allow($group, 'controllers/Pages/allinfo_reports_activities'); $this->Acl->allow($group, 'controllers/Pages/contact'); // registered $group->id = 3; $this->Acl->deny($group, 'controllers'); $this->Acl->allow($group, 'controllers/Users/login'); $this->Acl->allow($group, 'controllers/Users/logout'); $this->Acl->allow($group, 'controllers/Users/edit'); // organizations $this->Acl->allow($group, 'controllers/Organizations/index'); $this->Acl->allow($group, 'controllers/Organizations/index_mou'); $this->Acl->allow($group, 'controllers/Organizations/view'); // foreign organizations $this->Acl->allow($group, 'controllers/ForeignOrganizations/index'); $this->Acl->allow($group, 'controllers/ForeignOrganizations/view'); // people $this->Acl->allow($group, 'controllers/People/index'); $this->Acl->allow($group, 'controllers/People/index_member'); $this->Acl->allow($group, 'controllers/People/view'); // subtopics $this->Acl->allow($group, 'controllers/Subtopics/get'); // activities $this->Acl->allow($group, 'controllers/Activities/index'); $this->Acl->allow($group, 'controllers/Activities/index_member'); $this->Acl->allow($group, 'controllers/Activities/view'); $this->Acl->allow($group, 'controllers/Activities/getVisitors'); // pages $this->Acl->allow($group, 'controllers/Pages/index'); $this->Acl->allow($group, 'controllers/Pages/peopleMapThailand'); $this->Acl->allow($group, 'controllers/Pages/regions'); $this->Acl->allow($group, 'controllers/Pages/peopleMapRegions'); $this->Acl->allow($group, 'controllers/Pages/peopleMapProvinces'); $this->Acl->allow($group, 'controllers/Pages/provinces'); $this->Acl->allow($group, 'controllers/Pages/set_provinces_slugs'); $this->Acl->allow($group, 'controllers/Pages/error404'); $this->Acl->allow($group, 'controllers/Pages/admin_error404'); $this->Acl->allow($group, 'controllers/Pages/chartCountry'); $this->Acl->allow($group, 'controllers/Pages/chartPeopleCountry'); $this->Acl->allow($group, 'controllers/Pages/chartRegion'); $this->Acl->allow($group, 'controllers/Pages/chartPeopleRegion'); $this->Acl->allow($group, 'controllers/Pages/chartPeopleProvince'); $this->Acl->allow($group, 'controllers/Pages/chartProvince'); $this->Acl->allow($group, 'controllers/Pages/reports'); $this->Acl->allow($group, 'controllers/Pages/reports_organizations'); $this->Acl->allow($group, 'controllers/Pages/reports_people'); $this->Acl->allow($group, 'controllers/Pages/reports_activities'); $this->Acl->allow($group, 'controllers/Pages/allinfo_reports_organizations'); $this->Acl->allow($group, 'controllers/Pages/allinfo_reports_people'); $this->Acl->allow($group, 'controllers/Pages/allinfo_reports_activities'); $this->Acl->allow($group, 'controllers/Pages/contact'); //we add an exit to avoid an ugly "missing views" error message echo "all done"; exit; } }