Exemplo n.º 1
0
use Core\Form\Form;
use SocioChat\Forms\Rules;
use Zend\Config\Config;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'config.php';
$container = DI::get()->container();
DIBuilder::setupNormal($container);
$config = $container->get('config');
/* @var $config Config */
$email = isset($_REQUEST['email']) ? $_REQUEST['email'] : null;
$code = isset($_REQUEST['code']) ? $_REQUEST['code'] : null;
$validation = null;
if (!$email || !$code) {
    exit;
}
$form = new Form();
$form->import($_REQUEST);
$form->addRule(ActivationsDAO::EMAIL, Rules::email(), 'email в таком формате не может существовать.', 'emailPattern')->addRule(ActivationsDAO::EMAIL, function ($val) {
    $user = UserDAO::create()->getByEmail($val);
    return (bool) $user->getId();
}, 'Такой email не найден в системе.', 'userSearch');
$validation = $form->validate();
if (!$validation) {
    $heading = 'Ошибка!';
    $message = 'Email невалиден.';
    require_once "pages/common_page.php";
    exit;
}
$activation = ActivationsDAO::create();
$result = $activation->getActivation($email, $code);
$activation = $result[0];
/* @var $activation ActivationsDAO */
Exemplo n.º 2
0
session_start();
$email = isset($_REQUEST['email']) ? trim($_REQUEST['email']) : null;
$token = isset($_POST['token']) ? $_POST['token'] : null;
$sessionToken = isset($_SESSION['token']) ? $_SESSION['token'] : null;
function showFirst($email, $validation = null, Form $form = null)
{
    $token = PasswordUtils::get(20);
    $_SESSION['token'] = $token;
    require_once "pages/recovery/recovery1.php";
}
if (!$email || !$token) {
    showFirst($email);
    exit;
}
$form = new Form();
$form->import($_POST);
$form->addRule(ActivationsDAO::EMAIL, Rules::email(), 'email в таком формате не может существовать.', 'emailPattern')->addRule(ActivationsDAO::EMAIL, function ($val) {
    $user = UserDAO::create()->getByEmail($val);
    return (bool) $user->getId();
}, 'Такой email не найден в системе.', 'userSearch');
$validation = $form->validate();
if (!$validation || $sessionToken != $token) {
    showFirst($email, $validation, $form);
    exit;
}
// Поиск прежних активаций и аннуляция
$activation = ActivationsDAO::create();
$activation->getByEmail($email);
if ($activation->getId() && !$activation->getIsUsed()) {
    $activation->setIsUsed(true);
    $activation->save();