Пример #1
0
 /**
  * Saves an account to the db. If the id exists the given dataset will be updated
  * @param \Account\Model\Account $account
  *
  * @throws \Exception
  */
 public function saveAccount(Account $account)
 {
     $data = ['name' => $account->getName(), 'password' => $account->getPassword(), 'userhash' => $account->getUserHash(), 'email' => $account->getEmail(), 'role' => $account->getRole(), 'avatar' => $account->getAvatar(), 'date_registered' => $account->getDateRegistered(), 'mini' => $account->getMini()];
     if (!$account->getId()) {
         $data['password'] = hash('sha256', $account->getPassword()) . Constants::SALT;
         $this->tableGateway->insert($data);
     } else {
         if ($this->getAccount($account->getId())) {
             $this->tableGateway->update($data, ['id' => $account->getId()]);
         } else {
             throw new \Exception('Account id does not exist');
         }
     }
 }
Пример #2
0
 /**
  * @param Account $account
  *
  * @return int
  */
 private function authenticate($account)
 {
     $dbAcc = $this->getAccountTable()->getAccountBy(['name' => $account->getName()]);
     if (!$dbAcc) {
         return AUTH_RESULT::NOT_FOUND;
     }
     $hashedPw = hash('sha256', $account->getPassword()) . Constants::SALT;
     if ($hashedPw != $dbAcc->getPassword()) {
         return AUTH_RESULT::WRONG_CREDENTIALS;
     }
     if ($dbAcc->getRole() == Role::NOT_ACTIVATED) {
         return AUTH_RESULT::NOT_CONFIRMED;
     }
     return AUTH_RESULT::SUCCESS;
 }