Esempio n. 1
0
 /**
  * Loads a class and instantiate an object.
  * @param string $class class name
  * @param null $params
  * @param bool $instantiate
  * @param bool $force_new_object
  * @return object|bool
  */
 public static function &factory($class, $params = null, $instantiate = true, $force_new_object = false)
 {
     $class = strtolower($class);
     $path = str_replace('_', '/', $class);
     // If we would like to instantiate a new object,
     // we do not need to check the class existance.
     if ($force_new_object) {
         // Does the class exist? If so, we're done...
         if (isset(self::$_objects[$class])) {
             return self::$_objects[$class];
         }
     }
     $p = explode('/', $path);
     $filename = end($p);
     $path = implode('/', array_slice($p, 0, -1)) . '/';
     // Try to find a file
     $file = Exido::findFile($path, $filename, true);
     if (is_file($file)) {
         include_once $file;
         $name = $class;
         if ($force_new_object) {
             Helper::load('guid');
             $name = $name . '_' . guidGet();
         }
         if ($instantiate == false) {
             self::$_objects[$name] = true;
             return self::$_objects[$name];
         }
         self::$_objects[$name] = new $class($params);
         return self::$_objects[$name];
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Generate a random entity key. Using when creating an entity.
  * @param int $chars
  * @param int $groups
  * @param string $delimiter
  * @param bool $lowcase
  * @return string
  */
 private function _genEntityKey($chars = 8, $groups = 1, $delimiter = '', $lowcase = true)
 {
     Helper::load('guid');
     return guidGet($chars, $groups, $delimiter, $lowcase);
 }
Esempio n. 3
0
 /**
  * Users add page
  * @return void
  */
 public function create()
 {
     // Save when posting
     if ($this->input->checkPost()) {
         // Init validation object
         $v = Registry::factory('Validation_Form');
         // Set rules
         $v->setRule('user_name', 'required|alphaDash');
         $v->setRule('user_email', 'required|email');
         $v->setRule('role_name', 'required');
         // Set error messages
         $v->setRuleError('user_name', __('Please enter a user name'), 'required');
         $v->setRuleError('user_name', __('User name may contains only latin characters and numbers'), 'alphaDash');
         $v->setRuleError('user_email', __('Please enter a email'), 'required');
         $v->setRuleError('user_email', __('Please enter a valid email'), 'email');
         $v->setRuleError('role_name', __('Please choose role'), 'required');
         // Run validator
         if ($v->run()) {
             // If validation was passed successfully
             $this->db_user->setUser_name($this->input->post('user_name'));
             $this->db_user->setUser_email($this->input->post('user_email'));
             $this->db_user->setRole_key($this->input->post('role_name'));
             $this->db_user->setDescription($this->input->post('description'));
             // Generate unique session id
             $this->db_user->setUnique_session_id(guidGet(64, 1, '', true));
             // Set owner parameters
             $this->db_user->setOwner_id(constant('@SU.USER_ID'));
             $this->db_user->setOwner_name(constant('@SU.USER_NAME'));
             $this->db_user->setGroup_id(constant('@SU.GROUP_ID'));
             $this->db_user->setGroup_name(constant('@SU.GROUP_NAME'));
             $this->db_user->setPermissions_owner('rwx');
             $this->db_user->setPermissions_group('r--');
             $this->db_user->setPermissions_other('r--');
             // Set date and status
             $this->db_user->setCreated_at(dateConvert2SQL());
             // Set enabled
             if ($this->input->post('is_enabled')) {
                 $this->db_user->setIs_enabled(true);
             }
             $username = $this->input->post('user_name');
             // Generate password
             $password = $this->input->post('password');
             if ($password) {
                 $this->db_user->setPassword(md5($password));
             } else {
                 $password = guidGet(8, 1, '', true);
                 $this->db_user->setPassword(md5($password));
             }
             // Adding user
             if ($this->db_user->addUser()) {
                 $this->session->set('action_success', __('User has been successfully added.'));
                 // Email password to user
                 if ($this->input->post('do_not_email_password') == false) {
                     $this->_emailPassword($this->input->post('user_email'), $username, $password);
                 }
             } else {
                 // If something was wrong
                 $this->session->set('action_error', sprintf(__('There is an error while creating a user. Details: %s'), $this->db_page->getErrorString()));
             }
         } else {
             // If something was wrong during validation
             $this->session->set('action_error', sprintf(__('There is an error while creating a user. Details: %s'), $v->getErrorString()));
         }
         uriSiteRedirect('user');
     }
     $this->view->roles_list = $this->db_user->getRoleList();
 }