/** * @param \Generated\Shared\Transfer\UserTransfer $user * * @return string */ public function generateToken(UserTransfer $user) { return hash('sha256', sprintf('%s%s', $user->getPassword(), $user->getIdUser())); }
/** * @param \Generated\Shared\Transfer\UserTransfer $userTransfer * * @return \Generated\Shared\Transfer\UserTransfer */ public function save(UserTransfer $userTransfer) { if ($userTransfer->getIdUser() !== null) { $userEntity = $this->getEntityUserById($userTransfer->getIdUser()); } else { $userEntity = new SpyUser(); } $userEntity->setFirstName($userTransfer->getFirstName()); $userEntity->setLastName($userTransfer->getLastName()); $userEntity->setUsername($userTransfer->getUsername()); if ($userTransfer->getStatus() !== null) { $userEntity->setStatus($userTransfer->getStatus()); } if ($userTransfer->getLastLogin() !== null) { $userEntity->setLastLogin($userTransfer->getLastLogin()); } $password = $userTransfer->getPassword(); if (!empty($password) && $this->isRawPassword($userTransfer->getPassword())) { $userEntity->setPassword($this->encryptPassword($userTransfer->getPassword())); } $userEntity->save(); $userTransfer = $this->entityToTransfer($userEntity); return $userTransfer; }