示例#1
0
 /**
  * Create user to test
  *
  * @param  array                       $data
  * @return Application\Model\UserModel
  */
 protected function _createAuthUser(array $data)
 {
     $user = new Application\Model\UserModel($data);
     $user->save();
     self::initAuthUser($user);
     return $user;
 }
 public function testGeneratePassword()
 {
     $this->_user->save();
     $password1 = $this->_service->generatePassword(11);
     $password2 = $this->_service->generatePassword(11);
     $password3 = $this->_service->generatePassword();
     $this->assertNotEquals($password1, $password2);
     $this->assertEquals(11, strlen($password1));
     $this->assertEquals(10, strlen($password3));
 }
 /**
  *
  */
 public function testInsertLastUsedPasswords()
 {
     // Persist the user
     $this->user->save();
     $passwords = array('asjfdkj2i2', 'asdjfkjasfjl', 'asdfjkasjdfas');
     $result = $this->userMapper->insertLastUsedPasswords($this->user->getId(), $passwords);
     $this->assertNotNull($result);
     $this->assertEquals($passwords, $result['passwords']);
     return array($this->user->getId(), $passwords);
 }
 public function testRemoveUser()
 {
     $user = new UserModel($this->_data);
     $user->save();
     // Make sure it's been saved
     $user = UserModel::find($user->getId());
     $this->assertInstanceOf('\\Application\\Model\\UserModel', $user);
     $user->delete();
     $user = UserModel::find($user->getId());
     $this->assertNull($user);
 }
 /**
  *
  * @param  UserModel $user
  * @param  string    $reason
  * @return boolean
  */
 public function blockUser($user, $reason)
 {
     if ($user->getStatus() !== UserModel::USER_STATUS_BLOCKED) {
         // Block user
         $user->status = UserModel::USER_STATUS_BLOCKED;
         $user->save();
         \App::audit("User " . $user->getUserName() . " has been blocked due to {$reason}", $user);
         \App::log()->debug("User " . $user->getUserName() . " status changed to BLOCKED");
         $this->_sendEvent('update', $user);
         $this->_sendEvent('block', $user);
         return true;
     }
     return false;
 }