Exemple #1
0
 public function insert(UserModel $user)
 {
     $data = array('user_id' => $user->getUserId(), 'email' => $user->getEmail(), 'display_name' => $user->getDisplayName(), 'password' => $user->getPassword(), 'salt' => $user->getSalt(), 'register_time' => new Expr('NOW()'), 'register_ip' => new Expr("INET_ATON('{$_SERVER['REMOTE_ADDR']}')"));
     $db = $this->getWriteAdapter();
     $db->insert($this->getTableName(), $data);
     $userId = $db->lastInsertId();
     $user->setUserId($userId);
     return $user;
 }
Exemple #2
0
 public function testUserInitialState()
 {
     $user = new User();
     $this->assertNull($user->getLidnr());
     $this->assertNull($user->getEmail());
     $this->assertNull($user->getPassword());
     $this->assertNull($user->getMember());
     $this->assertEmpty($user->getRoleNames());
     $this->assertEquals('user_', $user->getRoleId());
     $this->assertEquals('user', $user->getResourceId());
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $user->getRoles());
     $this->assertEquals(0, count($user->getRoles()));
 }
Exemple #3
0
 public function updateUser(User $user)
 {
     $updateArray = array('username' => $user->getUsername() ?: null, 'role' => $user->getRole() ?: null, 'salt' => $user->getSalt() ?: null, 'password' => $user->getPassword() ?: null, 'fullName' => $user->getFullName() ?: null, 'gender' => $user->getGender() ?: null, 'birthdate' => $user->getBirthdate() ?: null, 'email' => $user->getEmail() ?: null, 'mobile' => $user->getMobile() ?: null, 'cityId' => (int) $user->getCityId() ?: null, 'districtId' => (int) $user->getDistrictId() ?: null, 'address' => $user->getAddress() ?: null, 'rememberMe' => $user->getRememberMe() ?: null, 'lastAccess' => $user->getLastAccess() ?: null, 'activeKey' => $user->getActiveKey() ?: null, 'resetKey' => $user->getResetKey() ?: null, 'active' => $user->getActive(), 'registeredDate' => $user->getRegisteredDate() ?: null, 'facebook' => $user->getFacebook() ?: null, 'description' => $user->getDescription() ?: null, 'locked' => $user->getLocked() ?: null);
     $updateArray = array_filter($updateArray, 'strlen');
     $updateArray = array_filter($updateArray);
     $update = $this->getDbSql()->update(self::TABLE_NAME);
     if ($user->getId()) {
         $update->where(array('id' => $user->getId()));
     }
     $update->set($updateArray);
     $query = $this->getDbSql()->buildSqlString($update);
     $result = $this->getDbAdapter()->query($query, Adapter::QUERY_MODE_EXECUTE);
     return $result;
 }
Exemple #4
0
 /**
  * @param \User\Model\User $user
  * @return boolean
  */
 public function updateUser(\User\Model\User $user)
 {
     if (!$user->getId() && !$user->getEmail() && !$user->getUsername()) {
         return false;
     }
     /* @var $userMapper \User\Model\UserMapper */
     $userMapper = $this->getServiceLocator()->get('User\\Model\\UserMapper');
     if ($user->getPassword()) {
         $user->setSalt(substr(md5(rand(2000, 5000) . time() . rand(2000, 5000)), 0, 20));
         $user->setPassword(md5($user->getSalt() . $user->getPassword()));
     }
     return $userMapper->updateUser($user);
 }
Exemple #5
0
 public function update(UserModel $user)
 {
     $sql = 'UPDATE user SET
             email=:email,
             username=:username,
             password=:password,
             firstname=:firstname,
             lastname=:lastname,
             birthdate=:birthdate,
             isActive=:isActive
             WHERE id=:id
            ';
     $this->getDb()->beginTransaction();
     try {
         $stmt = $this->getDb()->prepare($sql);
         $stmt->execute(array('email' => $user->getEmail(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'firstname' => $user->getFirstname(), 'lastname' => $user->getLastname(), 'birthdate' => $user->getBirthdate()->format('Y-m-d'), 'isActive' => $user->getIsActive(), 'id' => (int) $user->getId()));
         $this->getDb()->commit();
     } catch (PDOException $e) {
         $this->getDb()->rollBack();
         throw $e;
     }
 }
Exemple #6
0
 public function insert(UserModel $user)
 {
     $sql = 'INSERT INTO user VALUES (' . 'NULL, ' . "'" . $user->getEmail() . "'," . "'" . $user->getUsername() . "'," . "'" . $user->getPassword() . "'," . "'" . $user->getFirstname() . "'," . "'" . $user->getLastname() . "'," . "'" . $user->getBirthdate()->format('Y-m-d') . "'," . "'" . (int) $user->getIsActive() . "'" . ")";
     echo $sql;
     $this->getDb()->exec($sql);
 }
Exemple #7
0
 /**
  * Verify the password.
  *
  * @param UserModel $user
  *
  * @return boolean
  */
 protected function verifyPassword(UserModel $user)
 {
     return $this->bcrypt->verify($this->password, $user->getPassword());
 }