예제 #1
0
 /**
  * Init form
  *
  * @param string $data
  */
 public function initialize($data = null)
 {
     $description = new TextArea('description', ['rows' => 5, 'required' => 'required']);
     $this->add($description);
     $bugTrackingType = new Select('bug_tracking_type_id', BugTrackingType::find(['order' => 'ordering']), ['using' => ['id', 'name'], 'useEmpty' => true, 'required' => 'required']);
     $bugTrackingType->addValidator(new PresenceOf(['message' => 'Type is required']));
     $this->add($bugTrackingType);
     $bugTrackingPriority = new Select('bug_tracking_priority_id', BugTrackingPriority::find(['order' => 'ordering']), ['using' => ['id', 'name'], 'useEmpty' => true, 'required' => 'required']);
     $bugTrackingPriority->addValidator(new PresenceOf(['message' => 'Priority is required']));
     $this->add($bugTrackingPriority);
     $notify = new Select('role_id', UserRoles::find(['conditions' => 'location = 1']), ['using' => ['id', 'name'], 'useEmpty' => true, 'required' => 'required']);
     $notify->addValidator(new PresenceOf(['message' => 'Notify is required']));
     $this->add($notify);
 }
예제 #2
0
 /**
  * @param int|array $ids
  * @return bool
  */
 public static function updateModuleMenu($ids = null)
 {
     if ($ids != null) {
         if (is_array($ids)) {
             ZArrayHelper::toInteger($ids);
         } else {
             $id = intval($ids);
             $ids = [];
             $ids[] = $id;
         }
     }
     $menus = CoreModules::find(['conditions' => 'menu != "" AND location = "backend" AND published = 1 AND base_name NOT IN("admin","system","template")', 'order' => 'ordering ASC'])->toArray();
     if (!count($menus)) {
         $menus = [];
     }
     $menuAdmin = CoreModules::findFirst("base_name = 'admin'");
     $menuTemplate = CoreModules::findFirst("base_name = 'template'");
     $menuSystem = CoreModules::findFirst("base_name = 'system'");
     if ($menuTemplate) {
         array_unshift($menus, $menuAdmin->toArray());
     }
     if ($menuTemplate) {
         $menus[] = $menuTemplate->toArray();
     }
     if ($menuSystem) {
         $menus[] = $menuSystem->toArray();
     }
     $menusAll = [];
     foreach ($menus as $index => $menu) {
         $menusAll[] = unserialize($menu['menu']);
     }
     $newMenuAll = [];
     foreach ($menusAll as $menu) {
         if (isset($menu['link'])) {
             $menu['link'] = self::checkUrl($menu['link']);
             $tmp = $menu;
             $tmp['items'] = [];
             if (isset($menu['items']) && count($menu['items'])) {
                 foreach ($menu['items'] as $index1 => $item) {
                     if (isset($item['link'])) {
                         $item['link'] = self::checkUrl($item['link']);
                         $tmp['items'][$index1] = $item;
                         if (isset($item['items']) && count($item['items'])) {
                             foreach ($item['items'] as $index2 => $childItem) {
                                 $childItem['link'] = self::checkUrl($childItem['link']);
                                 $tmp['items'][$index1]['items'][$index2] = $childItem;
                             }
                         }
                     }
                 }
             }
             $newMenuAll[] = $tmp;
         }
     }
     $menusAll = $newMenuAll;
     if (count($ids)) {
         /**
          * @var UserRoles[] $roles
          */
         $roles = UserRoles::find('id IN (' . implode(',', $ids) . ')');
     } else {
         $roles = UserRoles::find();
     }
     $menuForRole = [];
     foreach ($roles as $role) {
         if ($role->role_id != 1) {
             $rules = UserRoles::getRules($role->role_id);
             if (count($rules)) {
                 $menuTMPArray = [];
                 foreach ($menusAll as $menu) {
                     if ($menu['rule'] == "" || self::checkRuleMenuInRole($menu['rule'], $rules)) {
                         $menuTMP = ['menu_name' => $menu['menu_name'], 'module' => $menu['module'], 'link' => $menu['link'], 'rule' => $menu['rule'], 'link_class' => $menu['link_class'], 'icon_class' => $menu['icon_class'], 'link_target' => $menu['link_target']];
                         $menuTMP['items'] = [];
                         if (isset($menu['items']) && count($menu['items'])) {
                             foreach ($menu['items'] as $index1 => $item) {
                                 if ($item['rule'] == "" || self::checkRuleMenuInRole($item['rule'], $rules)) {
                                     $childItem = [];
                                     if (isset($item['items'])) {
                                         $childItem = $item['items'];
                                     }
                                     $item['items'] = [];
                                     $menuTMP['items'][$index1] = $item;
                                     if (count($childItem)) {
                                         foreach ($childItem as $cItem) {
                                             if ($cItem['rule'] == "" || self::checkRuleMenuInRole($cItem['rule'], $rules)) {
                                                 $menuTMP['items'][$index1]['items'][] = $cItem;
                                             }
                                         }
                                     }
                                     if (!count($menuTMP['items'][$index1]['items']) && ($menuTMP['items'][$index1]['link'] == "" || $menuTMP['items'][$index1]['link'] == "#") && $menuTMP['items'][$index1]["role"] == "") {
                                         unset($menuTMP['items'][$index1]);
                                     }
                                 }
                             }
                         }
                         if (!count($menuTMP['items']) && ($menuTMP['link'] == "" || $menuTMP['link'] == "#") && $menuTMP["rule"] == "") {
                         } else {
                             $menuTMPArray[] = $menuTMP;
                         }
                     }
                 }
                 $menuForRole[$role->role_id] = $menuTMPArray;
             } else {
                 $menuForRole[$role->role_id] = null;
             }
         } else {
             $menuForRole[$role->role_id] = $menusAll;
         }
     }
     foreach ($roles as $role) {
         $role->menu = serialize($menuForRole[$role->role_id]);
         if (!$role->save()) {
             //Do something
         }
     }
     return true;
 }
예제 #3
0
 /**
  * Edit role
  *
  * @param int $id
  * @return null
  */
 public function editAction($id)
 {
     $id = intval($id);
     //Add toolbar button
     $this->_toolbar->addSaveButton();
     $this->_toolbar->addCancelButton('index');
     /**
      * @var Users $currentEditUser
      */
     $currentEditUser = Users::findFirst($id);
     //If id not exist
     if (!$currentEditUser || $currentEditUser->user_id == Users::getCurrentUser()['id']) {
         $this->flashSession->error('m_system_user_message_user_not_exist');
         $this->response->redirect('/admin/system/user/');
         return null;
     }
     $oldUserInfo = clone $currentEditUser;
     $currentEditUser->password = null;
     $form = new UserForm($currentEditUser);
     $this->view->setVar('admin_role', UserRoles::find());
     if ($this->request->isPost()) {
         if ($_POST['password'] == '' && $_POST['password_confirmation'] == '') {
             //Return old password
             $_POST['password'] = $oldUserInfo->password;
             $_POST['password_confirmation'] = $_POST['password'];
         }
         if ($form->isValid($_POST, $currentEditUser)) {
             $currentEditUser->avatar = USER_AVATAR_DEFAULT;
             $currentEditUser->email = $oldUserInfo->email;
             $currentEditUser->password = $this->security->hash($_POST['password']);
             if ($currentEditUser->save()) {
                 $this->flashSession->success('m_system_user_message_update_user_successfully');
                 return $this->response->redirect('/admin/system/user/');
             } else {
                 $this->flashSession->error('m_system_user_message_update_user_failed');
                 $this->setFlashSession($currentEditUser->getMessages(), 'error');
             }
         } else {
             $this->setFlashSession($form->getMessages(), 'error');
         }
     }
     $this->view->setVar('form', $form);
     $_POST['password'] = '';
     $_POST['password_confirmation'] = '';
     return true;
 }
예제 #4
0
파일: Users.php 프로젝트: kimthangatm/zcms
 /**
  * Login
  *
  * @param string $email
  * @param string $password
  * @return bool
  */
 public static function login($email, $password)
 {
     /**
      * @var Users $user
      */
     $user = Users::findFirst(['conditions' => 'is_active = 1 AND email = ?0', 'bind' => [$email]]);
     /**
      * @var \Phalcon\Security $security
      */
     $security = Di::getDefault()->get('security');
     if ($user && Users::checkPassword($password, $user->salt, $user->password)) {
         $token = $security->getToken();
         /**
          * @var UserRoles $role
          */
         $role = UserRoles::findFirst($user->role_id);
         $acl = json_decode($role->acl, true);
         /**
          * @var \ZCMS\Core\ZSession $session
          */
         $session = Di::getDefault()->get('session');
         $session->set('auth', ['full_name' => $user->first_name . ' ' . $user->last_name, 'email' => $user->email, 'id' => $user->user_id, 'role' => $user->role_id, 'rules' => $acl['rules'], 'gender' => $user->gender, 'linkAccess' => $acl['links'], 'language' => $user->language_code, 'avatar' => $user->avatar, 'token' => $token, 'coin' => (double) $user->coin, 'created_at' => date('Y-m-d', strtotime($user->created_at)), 'is_super_admin' => $role->is_super_admin, 'last_use_admin' => time()]);
         return true;
     }
     return false;
 }
예제 #5
0
 /**
  * Update user in send email activate login with social
  *
  * @return bool
  */
 private function _generateActiveAccountWithSocial()
 {
     $defaultCustomerRoleID = UserRoles::getDefaultCustomerRoleID();
     if ($defaultCustomerRoleID) {
         $this->user->active_account_token = randomString(100) . time() . '_' . base64_encode($this->socialName);
         $this->user->active_account_type = $this->socialName;
         $this->user->is_active = 0;
         if ($this->socialName == 'facebook' && isset($this->userInfo['facebook_id'])) {
             $this->user->facebook_id = $this->userInfo['facebook_id'];
         }
         if (!$this->user->role_id) {
             $this->user->role_id = $defaultCustomerRoleID;
         }
         $data = ['active_account_token' => $this->user->active_account_token, 'email' => $this->user->email, 'first_name' => $this->user->first_name, 'last_name' => $this->user->last_name];
         $email = ZEmail::getInstance();
         if ($this->user->save()) {
             $email->setSubject('_ZT_Activate Account')->addTo($this->user->email, $this->user->first_name . $this->user->last_name)->setTemplate('auth', 'register_with_' . $this->socialName, $data)->send();
             return true;
         }
     }
     return false;
 }
예제 #6
0
 /**
  * List all bug notify to me
  */
 public function bugAndRequestNotifyToMeAction()
 {
     $this->_toolbar->addBreadcrumb(['title' => 'Bug tracking']);
     $this->_toolbar->addBreadcrumb(['title' => 'Notify To Me']);
     $this->_toolbar->addHeaderPrimary('Tracking notify to your group');
     $this->_toolbar->addHeaderSecond('Notify To Me');
     $this->_toolbar->addNewButton('bugtracking|index|new', '/admin/bugtracking/index/new/', 'New Bug / Request');
     $this->addFilterInList();
     $filter = $this->getFilter();
     $conditions = $this->getConditions($filter);
     //View notify create by Current user OR notify to Current User Role
     $conditions[] = '(b.role_id = ' . $this->_user['role'] . ')';
     $condition = implode(' AND ', $conditions);
     $this->setItemsToView($condition, $filter);
     //Set column name, value
     $_pageLayout = [['type' => 'check_all'], ['type' => 'index', 'title' => '#'], ['type' => 'link', 'title' => 'Description', 'class' => 'view-bug-tracking', 'access' => $this->acl->isAllowed('bugtracking|index|view'), 'link' => $this->linkView, 'column' => 'description', 'filter' => ['type' => 'text', 'name' => 'filter_description']]];
     $_pageLayout[] = ['type' => 'text', 'title' => 'Type', 'label' => [['condition' => '==', 'condition_value' => 'Feature Request', 'class' => 'label z-label label-sm label-success', 'text' => 'Request'], ['condition' => '==', 'condition_value' => 'Bug Tracking', 'class' => 'label z-label label-sm label-warning', 'text' => 'Bug']], 'column' => 'btt_name', 'class' => 'text-center', 'css' => 'width: 110px;', 'filter' => ['type' => 'select', 'name' => 'filter_bug_tracking_type', 'attributes' => ['useEmpty' => true, 'emptyText' => 'All', 'value' => $filter['filter_bug_tracking_type'] == '' ? -1 : $filter['filter_bug_tracking_type'], 'using' => ['id', 'name']], 'value' => BugTrackingType::find(['oder' => 'ordering ASC'])]];
     $_pageLayout[] = ['type' => 'text', 'title' => 'Priority', 'column' => 'btp_name', 'class' => 'text-center', 'css' => 'width: 120px;', 'filter' => ['type' => 'select', 'name' => 'filter_bug_tracking_priority', 'attributes' => ['useEmpty' => true, 'emptyText' => 'All', 'value' => $filter['filter_bug_tracking_priority'] == '' ? -1 : $filter['filter_bug_tracking_priority'], 'using' => ['id', 'name']], 'value' => BugTrackingPriority::find(['oder' => 'ordering ASC'])]];
     $_pageLayout[] = ['type' => 'text', 'title' => 'Notify To', 'column' => 'name', 'class' => 'text-center', 'css' => 'width: 160px;', 'filter' => ['type' => 'select', 'name' => 'filter_user_role', 'attributes' => ['useEmpty' => true, 'emptyText' => 'All', 'value' => $filter['filter_user_role'] == '' ? -1 : $filter['filter_user_role'], 'using' => ['id', 'name']], 'value' => UserRoles::find(['conditions' => 'location = 1', 'oder' => 'name ASC'])]];
     $_pageLayout[] = ['type' => 'text', 'title' => 'Submitted By', 'column' => 'full_name', 'class' => 'text-center'];
     $_pageLayout[] = ['type' => 'date', 'title' => 'gb_created_at', 'column' => 'b_created_at', 'filter' => ['type' => 'dateRange', 'name' => 'filter_created_at', 'attributes' => []]];
     $_pageLayout[] = ['type' => 'text', 'title' => 'Status', 'label' => [['condition' => '==', 'condition_value' => 'Done', 'class' => 'label z-label label-sm label-success'], ['condition' => '==', 'condition_value' => 'Waiting Process', 'class' => 'label z-label label-default'], ['condition' => '==', 'condition_value' => 'In Progress', 'class' => 'label z-label label-info']], 'css' => 'width: 120px', 'class' => 'text-center', 'column' => 'bug_tracking_status', 'filter' => ['type' => 'select', 'name' => 'filter_bug_tracking_status', 'attributes' => ['useEmpty' => true, 'emptyText' => 'All', 'value' => $filter['filter_bug_tracking_status'] == '' ? -1 : $filter['filter_bug_tracking_status'], 'using' => ['id', 'name']], 'value' => BugTrackingStatus::find(['oder' => 'ordering ASC'])]];
     $_pageLayout[] = ['type' => 'id', 'title' => 'ID', 'column' => 'id', 'css' => 'width: 70px', 'filter' => ['type' => 'text', 'name' => 'filter_id']];
     $this->view->setVar('_pageLayout', $_pageLayout);
 }
예제 #7
0
 /**
  * Get menu with admin user role
  *
  * @param integer $role
  * @return array|mixed
  */
 private function _getMenuAdmin($role)
 {
     $currentLink = '/admin/' . $this->_module . '/' . $this->_controller;
     $role = UserRoles::findFirst(['conditions' => 'role_id = ?0', 'bind' => [$role]]);
     if ($role) {
         /**
          * @var mixed $role
          */
         $menu = unserialize($role->menu);
         foreach ($menu as $lv1 => $item) {
             if (isset($item['items']) && count($item['items'])) {
                 foreach ($item['items'] as $lv2 => $childItem) {
                     if (isset($childItem['items']) && count($childItem['items'])) {
                         foreach ($childItem['items'] as $lv3 => $cChildItem) {
                             if (strpos($cChildItem['link'], $currentLink) !== false) {
                                 $menu[$lv1]['items'][$lv2]['current'] = 1;
                             }
                         }
                     }
                 }
             }
         }
         return $menu;
     }
     return [];
 }
예제 #8
0
 /**
  * Unpublished item action
  *
  * @param int $id
  * @param string $redirect
  * @param bool $log
  */
 public function unPublishAction($id = null, $redirect = null, $log = true)
 {
     if (class_exists($this->_model) && $this->_modelBaseName) {
         if ($log) {
             $extraQuery = ', updated_by = ' . $this->_user['id'] . ", updated_at = '" . date("Y-m-d H:i:s") . "'";
         } else {
             $extraQuery = null;
         }
         $ids = [];
         if ($id) {
             $id = intval($id);
             $ids[] = $id;
         } else {
             $ids = $this->request->getPost('ids');
             ZArrayHelper::toInteger($ids);
         }
         if (is_array($ids)) {
             ZArrayHelper::toInteger($ids);
             $query = "UPDATE {$this->_modelBaseName} SET published = 0 " . $extraQuery . " WHERE is_core = 0 AND module_id IN (" . implode(',', $ids) . ")";
             $this->db->execute($query);
             $this->flashSession->success(__('m_' . $this->_module . '_' . $this->_controller . '_message_items_successfully_unpublished', ["1" => $this->db->affectedRows()]));
             UserRoles::updateModuleMenu();
         }
     } else {
         $this->flashSession->error('gb_message_you_are_must_set_model_in_child_controller');
     }
     if ($redirect) {
         $this->response->redirect($redirect);
     } else {
         $this->response->redirect('/admin/' . $this->_module . '/' . $this->_controller . '/');
     }
 }
예제 #9
0
 private function updateACLCache()
 {
     /**
      * @var UserRoles[] $roles
      */
     $roles = UserRoles::find();
     foreach ($roles as $role) {
         $query = 'SELECT module, controller, action, sub_action, mca FROM user_rules AS al
                   INNER JOIN user_role_mapping AS alm ON alm.rule_id = al.rule_id
                   WHERE alm.role_id = ' . $role->role_id;
         $rules = $this->db->fetchAll($query, Db::FETCH_ASSOC);
         $rulesTmp = [];
         $linkAccess = [];
         foreach ($rules as $rule) {
             $rulesTmp[] = strtolower($rule['mca']);
             $linkAccess[] = strtolower('/admin/' . $rule['module'] . '/' . $rule['controller'] . '/' . $rule['action']);
             $rule['sub_action'] = trim($rule['sub_action'], ' ');
             if ($rule['sub_action']) {
                 $subAction = explode(',', $rule['sub_action']);
                 foreach ($subAction as $action) {
                     $action = trim($action, ' ');
                     if ($action != '') {
                         //Add Rule
                         $rulesTmp[] = strtolower($rule['module'] . '|' . $rule['controller'] . '|' . $action);
                         $linkAccess[] = strtolower('/admin/' . $rule['module'] . '/' . $rule['controller'] . '/' . $action);
                     }
                 }
             }
         }
         $role->acl = json_encode(['rules' => $rulesTmp, 'links' => $linkAccess]);
         $role->save();
     }
 }
예제 #10
-1
 /**
  * Init user form
  *
  * @param \ZCMS\Core\Models\Users $data
  */
 public function initialize($data = null)
 {
     //Add first name
     $firstName = new Text('first_name', ['maxlength' => '32']);
     $firstName->addValidator(new PresenceOf());
     $this->add($firstName);
     //Add last name
     $lastName = new Text('last_name', ['maxlength' => '32']);
     $lastName->addValidator(new PresenceOf());
     $this->add($lastName);
     //Add email
     if ($data = null) {
         $email = new Email('email', ['maxlength' => '128', 'readonly' => 'readonly']);
     } else {
         $email = new Email('email', ['maxlength' => '128']);
     }
     $this->add($email);
     //Add active
     $is_active = new Select('is_active', ['1' => __('gb_yes'), '0' => __('gb_no')]);
     $this->add($is_active);
     //Add password confirmation
     $password_confirmation = new Password('password_confirmation', ['maxlength' => '32']);
     $password_confirmation->addValidator(new StringLength(['min' => 6]));
     $this->add($password_confirmation);
     //Add password
     $password = new Password('password', ['maxlength' => '32']);
     $password->addValidator(new StringLength(['min' => 6]));
     $password->addValidator(new Confirmation(['message' => 'm_system_user_message_password_does_not_match_confirmation', 'with' => 'password_confirmation']));
     $this->add($password);
     //Add role
     $dbRoles = UserRoles::find(['conditions' => 'is_super_admin = 0', 'order' => 'is_default DESC']);
     $role = new Select('role_id', $dbRoles, ['using' => ['role_id', 'name']]);
     $role->addValidator(new InclusionIn(['message' => 'm_system_user_message_please_choose_role', 'domain' => array_column($dbRoles->toArray(), 'role_id')]));
     $this->add($role);
 }