<commit_before><?php

use MyApp\ChatConfig;
use MyApp\DAO\ActivationsDAO;
use MyApp\DAO\UserDAO;
use MyApp\Forms\Form;
use MyApp\Forms\Rules;
use MyApp\Utils\PasswordUtils;

require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config.php';
session_start();

$email = isset($_POST['email']) ? trim($_POST['email']) : null;
$token = isset($_POST['token']) ? $_POST['token'] : null;
$sessionToken = isset($_SESSION['token']) ? $_SESSION['token'] : null;
$validation = null;

function showFirst() {
	$token = PasswordUtils::get(20);
	$_SESSION['token'] = $token;
	require_once "pages/recovery1.php";
}

if (!$email || !$token) {
	showFirst();
	exit;
}

$form = new Form();
$form->import($_POST);
$form
	->addRule('email', Rules::email(), 'email в таком формате не может существовать.', 'emailPattern')
	->addRule(
		'email',
		function($val) {
			$user = UserDAO::create()->getByEmail($val);
			return (bool) $user->getId();
		},
		'Такой email не найден в системе.',
		'userSearch'
	);

$validation = $form->validate();

if (!$validation || $sessionToken != $token) {
	showFirst();
	exit;
}


// Поиск прежних активаций и аннуляция
$activation = ActivationsDAO::create();
$activation->getByEmail($email);

if ($activation->getId() && !$activation->getIsUsed()) {
	$activation->setIsUsed(true);
	$activation->save();
}

// Делаем активационный код
$activation = ActivationsDAO::create();
$activation->fillParams(
	[
		'email' => $email,
		'code' => substr(base64_encode(PasswordUtils::get(64)), 0, 64),
		'timestamp' => date('Y-m-d H:i:s'),
		'used' => false
	]
);
$activation->save();

$config = ChatConfig::get()->getConfig();
$mailerName = 'СоциоЧат';
$headers  = "MIME-Version: 1.0 \n"<commit_msg>fixes<commit_after><?php

use MyApp\ChatConfig;
use MyApp\DAO\ActivationsDAO;
use MyApp\DAO\UserDAO;
use MyApp\Forms\Form;
use MyApp\Forms\Rules;
use MyApp\Utils\PasswordUtils;

require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config.php';
session_start();

$email = isset($_POST['email']) ? trim($_POST['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/recovery1.php";
}

if (!$email || !$token) {
	showFirst($email);
	exit;
}

$form = new Form();
$form->import($_POST);
$form
	->addRule('email', Rules::email(), 'email в таком формате не может существовать.', 'emailPattern')
	->addRule(
		'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();
}

// Делаем активационный код
$activation = ActivationsDAO::create();
$activation->fillParams(
	[
		'email' => $email,
		'code' => substr(base64_encode(PasswordUtils::get(64)), 0, 64),
		'timestamp' => date('Y-m-d H:i:s'),
		'used' => false
	]
);
$activation->save();

$config = ChatConfig::get()->getConfig();
$mailerName = 'СоциоЧат';
$headers  = "MIME-Version: 1.0 \n"
{'fraction_non_alphanumeric': 0.20757444348077478, 'fraction_numerical': 0.006938421509106678, 'mean_word_length': 5.666666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7414523', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1304, 'n_words': 244}