Пример #1
0
 protected function beforeValidate()
 {
     if (empty($this->slug) && !empty($this->title)) {
         $this->slug = $this->generateSlug();
     }
     return parent::beforeValidate();
 }
Пример #2
0
 /**
  *
  */
 protected function beforeValidate()
 {
     if (!$this->get('metadata.creator')) {
         $identity = \Dsc\System::instance()->get('auth')->getIdentity();
         if (!empty($identity->id)) {
             $this->set('metadata.creator', array('id' => $identity->id, 'name' => $identity->fullName()));
         } else {
             $this->set('metadata.creator', array('id' => \Dsc\System::instance()->get('session')->id(), 'name' => 'session'));
         }
     }
     if (!empty($this->items)) {
         $this->items = array_values($this->items);
     }
     if (empty($this->number)) {
         $this->number = $this->createNumber();
     }
     return parent::beforeValidate();
 }
Пример #3
0
 protected function beforeValidate()
 {
     if (!empty($this->new_password)) {
         if (empty($this->confirm_new_password)) {
             $this->setError('Must confirm new password');
         }
         if ($this->new_password != $this->confirm_new_password) {
             $this->setError('New password and confirmation value do not match');
         }
         $this->password = password_hash($this->new_password, PASSWORD_DEFAULT);
     }
     unset($this->new_password);
     unset($this->confirm_new_password);
     $user = \Dsc\System::instance()->get('auth')->getIdentity();
     if ($user->role != 'root') {
         // do not allow to change user role unless the current user is in root group
         $old_role = 'unidentified';
         if (!empty($this->id)) {
             $old_user = (new \Users\Models\Users())->setState('filter.id', $this->id)->getItem();
             $old_role = $old_user->role;
         }
         $this->role = $old_role;
     }
     if (empty($this->password)) {
         $this->__auto_password = $this->generateRandomString(10);
         // save this for later emailing to the user, if necessary
         $this->password = password_hash($this->__auto_password, PASSWORD_DEFAULT);
     }
     $this->full_name = $this->fullName();
     return parent::beforeValidate();
 }