Пример #1
0
 /**
  * Creates a user session in the user namespace.
  * id, role, name, avatar and registered are accessable afterwards.
  * @param \Account\Model\Account $account
  */
 public static function createUserSession(Account $account)
 {
     $session = new Container('user');
     $session->id = $account->getId();
     $session->role = $account->getRole();
     $session->name = $account->getName();
     $session->avatar = $account->getAvatar();
     $session->registered = $account->getDateRegistered();
 }
Пример #2
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');
         }
     }
 }