add correct verification

master
Corné Oppelaar 9 years ago
parent ec9bedadd2
commit 23cdfd3bed
No known key found for this signature in database
GPG Key ID: FF32F66315D2E8E5

@ -2,9 +2,9 @@
cd "$(realpath "$(dirname "$0")/..")"; cd "$(realpath "$(dirname "$0")/..")";
composer install; composer install;
mkdir storage; test -d storage || mkdir storage;
touch storage/db.sqlite; touch storage/db.sqlite;
./vendor/bin/propel sql:build ./vendor/bin/propel sql:build --overwrite;
./vendor/bin/propel sql:insert; ./vendor/bin/propel sql:insert;
echo "Done setting up web environment" echo "Done setting up web environment"

@ -34,6 +34,15 @@ class Action extends Main
return $this->redirect('/login'); return $this->redirect('/login');
} }
$email = $loggedUser->getEmailAddressRelatedByEmail();
if ($email !== null || !$email->isVerified()) {
$segment->setFlash("message", "Please verify your email before logging in");
$segment->setFlash('username', $username);
return $this->redirect('/login');
}
$segment->set('userId', $loggedUser->getId()); $segment->set('userId', $loggedUser->getId());
$afterLogin = $segment->get('afterLogin'); $afterLogin = $segment->get('afterLogin');

@ -3,8 +3,63 @@
namespace Eater\Glim\Handler\Verify; namespace Eater\Glim\Handler\Verify;
use Eater\Glim\Handler\Session; use Eater\Glim\Handler\Session;
use Eater\Glim\Model\EmailAddressQuery;
use Eater\Glim\Service\User;
class Action extends Session class Action extends Session
{ {
protected $shouldHaveUser = false;
public function handle()
{
$verify = $this->attr('verify');
$verifyParts = explode('-', $verify, 2);
if (count($verifyParts) < 2) {
return $this->notFound();
}
$username = $this->post('username');
$password = $this->post('password');
/* @var User $user */
$user = $this->get('user');
/* @var \Aura\Session\Session $session */
$session = $this->get('session');
$segment = $session->getSegment('main');
$loggedUser = $user->login($username, $password);
if ($loggedUser === null) {
$segment->setFlash("message", "Login failed, username or password are incorrect");
$segment->setFlash('username', $username);
return $this->redirect($this->getRequest()->getUri()->getPath());
}
$segment->set('userId', $loggedUser->getId());
$id = intval($verifyParts[0]);
$verification = $verifyParts[1];
$email = $loggedUser->getEmailAddressRelatedByEmail();
if ($email === null || $email->getId() !== $id || $email->getVerified()) {
return $this->notFound();
}
$email = EmailAddressQuery::create()->findOneById($id);
if ($email === null || $email->getVerified() || $email->getVerification() !== $verification) {
return $this->notFound();
}
$email->setVerified(true);
$email->save();
$segment->setFlash('message', 'Successfully verified "' . $email->getAddress() .'"');
return $this->redirect('/panel');
}
} }
Loading…
Cancel
Save