/** * Auth user by email & passwd * * @param string $email * @param string $password * * @return bool|User */ public function auth(string $email, string $password) { $entityManager = $this->getEntityManager(); /** @var User $model */ $model = $entityManager->getRepository('thewulf7\\friendloc\\models\\User')->findOneBy(['email' => $email]); if (!$model) { return false; } $hashpasswd = crypt($password, $model->getSalt()); if ($hashpasswd === $model->getPasswd()) { $hash = hash('sha1', time() . '|' . $model->getId()); $model->setUserhash($hash); $entityManager->flush(); Auth::setAuth($hash); return $model; } else { return false; } }
/** * Approve user * * @param $hash */ public function approveAction(string $hash) { try { $model = $this->getAuthService()->authByHash($hash); if ($model) { $hash = hash('sha1', time() . '|' . $model->getId()); $model->setUserhash($hash); $model->setApproved(true); $this->getEntityManager()->persist($model); $this->getEntityManager()->flush(); Auth::setAuth($hash); $this->getEmailService()->sendSuccessEmail($model); $this->redirect('/'); } else { echo 'Wrong hash given.'; } } catch (\Exception $e) { echo 'Wrong hash given.'; } }