public function activate($token = null)
    {
        $activated = false;
        if ($token === null) {
            $this->redirect('/');
        }

        $this->loadModel('User.Users');
        $user = $this->Users
            ->find()
            ->select(['id', 'name', 'token'])
            ->where(['status' => 0, 'token' => $token])
            ->limit(1)
            ->first();

        if ($user) {
            if ($this->Users->updateAll(['status' => 1], ['id' => $user->id])) {
                NotificationManager::activated($user)->send();
                $activated = true;
                $this->Flash->success(__d('user', 'Account successfully activated.'), ['key' => 'activate']);
            } else {
                $this->Flash->danger(__d('user', 'Account could not be activated, please try again later.'), ['key' => 'activate']);
            }
        } else {
            $this->Flash->warning(__d('user', 'Account not found or is already active.'), ['key' => 'activate']);
        }

        $this->title(__d('user', 'Account Activation'));
        $this->set(compact('activated', 'token'));
    }
public function activate($token = null)
    {
        $activated = false;
        if ($token === null) {
            $this->redirect('/');
        }

        $this->loadModel('User.Users');
        $user = $this->Users
            ->find()
            ->select(['id', 'name', 'token'])
            ->where(['status' => 0, 'token' => $token])
            ->limit(1)
            ->first();

        if ($user) {
            if ($this->Users->updateAll(['status' => 1], ['id' => $user->id])) {
                NotificationManager::activated($user)->send();
                $activated = true;
                $this->Flash->success(__d('user', 'Account successfully activated.'), ['key' => 'activate']);
            } else {
                $this->Flash->danger(__d('user', 'Account could not be activated, please try again later.'), ['key' => 'activate']);
            }
        } else {
            $this->Flash->warning(__d('user', 'Account not found or is already active.'), ['key' => 'activate']);
        }

        $this->title(__d('user', 'Account Activation'));
        $this->set(compact('activated', 'token'));
    }
public function activate ( $ token = null ) { $ activated = false ; if ( $ token === null ) { $ this -> redirect ( '/' ) ; } $ this -> loadModel ( 'User.Users' ) ; $ user = $ this -> Users -> find ( ) -> select ( [ 'id' , 'name' , 'token' ] ) -> where ( [ 'status' => 0 , 'token' => $ token ] ) -> limit ( 1 ) -> first ( ) ; if ( $ user ) { if ( $ this -> Users -> updateAll ( [ 'status' => 1 ] , [ 'id' => $ user -> id ] ) ) { NotificationManager :: activated ( $ user ) -> send ( ) ; $ activated = true ; $ this -> Flash -> success ( __d ( 'user' , 'Account successfully activated.' ) , [ 'key' => 'activate' ] ) ; } else { $ this -> Flash -> danger ( __d ( 'user' , 'Account could not be activated, please try again later.' ) , [ 'key' => 'activate' ] ) ; } } else { $ this -> Flash -> warning ( __d ( 'user' , 'Account not found or is already active.' ) , [ 'key' => 'activate' ] ) ; } $ this -> title ( __d ( 'user' , 'Account Activation' ) ) ; $ this -> set ( compact ( 'activated' , 'token' ) ) ; }
Activates a registered user.

@param string $token A valid user token
@return void
Activates a registered user .