public function block($id)
    {
        $this->loadModel('User.Users');
        $user = $this->Users->get($id, [
            'fields' => ['id', 'name', 'email'],
            'contain' => ['Roles'],
        ]);

        if (!in_array(ROLE_ID_ADMINISTRATOR, $user->role_ids)) {
            if ($this->Users->updateAll(['status' => 0], ['id' => $user->id])) {
                $this->Flash->success(__d('user', 'User {0} was successfully blocked!', $user->name));
                $user->updateToken();
                NotificationManager::blocked($user)->send();
            } else {
                $this->Flash->danger(__d('user', 'User could not be blocked, please try again.'));
            }
        } else {
            $this->Flash->warning(__d('user', 'Administrator users cannot be blocked.'));
        }

        $this->title(__d('user', 'Block User Account'));
        $this->redirect($this->referer());
    }
public function block($id)
    {
        $this->loadModel('User.Users');
        $user = $this->Users->get($id, [
            'fields' => ['id', 'name', 'email'],
            'contain' => ['Roles'],
        ]);

        if (!in_array(ROLE_ID_ADMINISTRATOR, $user->role_ids)) {
            if ($this->Users->updateAll(['status' => 0], ['id' => $user->id])) {
                $this->Flash->success(__d('user', 'User {0} was successfully blocked!', $user->name));
                $user->updateToken();
                NotificationManager::blocked($user)->send();
            } else {
                $this->Flash->danger(__d('user', 'User could not be blocked, please try again.'));
            }
        } else {
            $this->Flash->warning(__d('user', 'Administrator users cannot be blocked.'));
        }

        $this->title(__d('user', 'Block User Account'));
        $this->redirect($this->referer());
    }
public function block ( $ id ) { $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> get ( $ id , [ 'fields' => [ 'id' , 'name' , 'email' ] , 'contain' => [ 'Roles' ] , ] ) ; if ( ! in_array ( ROLE_ID_ADMINISTRATOR , $ user -> role_ids ) ) { if ( $ this -> Users -> updateAll ( [ 'status' => 0 ] , [ 'id' => $ user -> id ] ) ) { $ this -> Flash -> success ( __d ( 'user' , 'User {0} was successfully blocked!' , $ user -> name ) ) ; $ user -> updateToken ( ) ; NotificationManager :: blocked ( $ user ) -> send ( ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'User could not be blocked, please try again.' ) ) ; } } else { $ this -> Flash -> warning ( __d ( 'user' , 'Administrator users cannot be blocked.' ) ) ; } $ this -> title ( __d ( 'user' , 'Block User Account' ) ) ; $ this -> redirect ( $ this -> referer ( ) ) ; }
Blocks the given user account.

After account is blocked token is regenerated, so user cannot login using
a known token.

@param int $id User's ID
@return void Redirects to previous page
Blocks the given user account .