예제 #1
0
 /**
  * Removes the given user.
  *
  * @param int $id User's ID
  * @return void Redirects to previous page
  */
 public function delete($id)
 {
     $this->loadModel('User.Users');
     $user = $this->Users->get($id, ['contain' => ['Roles']]);
     if (in_array(ROLE_ID_ADMINISTRATOR, $user->role_ids) && $this->Users->countAdministrators() === 1) {
         $this->Flash->danger(__d('user', 'You cannot remove this user as it is the last administrator available.'));
     } else {
         if ($this->Users->delete($user)) {
             NotificationManager::canceled($user)->send();
             $this->Flash->success(__d('user', 'User successfully removed!'));
             $this->redirect($this->referer());
         } else {
             $this->Flash->danger(__d('user', 'User could not be removed.'));
         }
     }
     $this->title(__d('user', 'Remove User Account'));
     $this->redirect($this->referer());
 }
 /**
  * test __callStatic() for welcome().
  *
  * @return void
  */
 public function testCallStaticWelcome()
 {
     $user = new User();
     $welcomeMessage = NotificationManager::welcome($user);
     $this->assertInstanceOf('User\\Notification\\Message\\WelcomeMessage', $welcomeMessage);
 }
예제 #3
0
 /**
  * Activates a registered user.
  *
  * @param string $token A valid user token
  * @return void
  */
 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'));
 }