Exemplo n.º 1
0
 public function update($data = array())
 {
     if (!panel()->user()->isAdmin() and !$this->isCurrent()) {
         throw new Exception(l('users.form.error.update.rights'));
     }
     // users which are not an admin cannot change their role
     if (!panel()->user()->isAdmin()) {
         unset($data['role']);
     }
     if (str::length(a::get($data, 'password')) > 0) {
         if (a::get($data, 'password') !== a::get($data, 'passwordconfirmation')) {
             throw new Exception(l('users.form.error.password.confirm'));
         }
     } else {
         unset($data['password']);
     }
     unset($data['passwordconfirmation']);
     if ($this->isLastAdmin() and a::get($data, 'role') !== 'admin') {
         // check the number of left admins to not convert the last one
         throw new Exception(l('user.error.lastadmin'));
     }
     parent::update($data);
     // flush the cache in case if the user data is
     // used somewhere on the site (i.e. for profiles)
     kirby()->cache()->flush();
     kirby()->trigger('panel.user.update', $this);
     return $this;
 }
Exemplo n.º 2
0
 public function update($data = array())
 {
     if (!panel()->user()->isAdmin() and !$this->isCurrent()) {
         throw new Exception(l('users.form.error.update.rights'));
     }
     if (str::length(a::get($data, 'password')) > 0) {
         if (a::get($data, 'password') !== a::get($data, 'passwordconfirmation')) {
             throw new Exception(l('users.form.error.password.confirm'));
         }
     } else {
         unset($data['password']);
     }
     unset($data['passwordconfirmation']);
     if ($this->isLastAdmin() and a::get($data, 'role') !== 'admin') {
         // check the number of left admins to not convert the last one
         throw new Exception(l('user.error.lastadmin'));
     }
     parent::update($data);
     kirby()->trigger('panel.user.update', $this);
     return $this;
 }