fix register email
This commit is contained in:
parent
9e446563b2
commit
bc6c35167e
@ -72,35 +72,37 @@ class SecureController extends AdminController
|
||||
*/
|
||||
public function actionEmailAuth(): void
|
||||
{
|
||||
$mailing = new Mailing();
|
||||
|
||||
$loginForm = new LoginEmailForm();
|
||||
$loginForm->load($_REQUEST);
|
||||
$email = $loginForm->getItem("email");
|
||||
$code = mt_rand(100000, 999999);
|
||||
|
||||
$email = $loginForm->getItem("email");
|
||||
$user = $this->userService->getByField('email', $email);
|
||||
|
||||
if (!$user){
|
||||
$newUser = new User();
|
||||
$newUser->email = $email;
|
||||
$newUser->username = substr($email, 0, strpos($email, "@"));
|
||||
$newUser->password_hash = password_hash(md5(microtime() . bin2hex(random_bytes(10)) . time()), PASSWORD_DEFAULT);
|
||||
$newUser->auth_code = $code;
|
||||
$newUser->auth_code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));
|
||||
$newUser->save();
|
||||
$password = md5(microtime() . bin2hex(random_bytes(10)) . time());
|
||||
UserService::createUserByEmailAndPassword($email, $password);
|
||||
$user = $this->userService->getByField('email', $email);
|
||||
|
||||
$mailing->send_html("register_by_code.php", ['code' => $user->auth_code, 'password' => $password], [
|
||||
'address' => $email,
|
||||
'subject' => "Код регистрации",
|
||||
"from_name" => $_ENV['APP_NAME']
|
||||
]);
|
||||
} else {
|
||||
$user->auth_code = $code;
|
||||
$user->auth_code = mt_rand(100000, 999999);;
|
||||
$user->auth_code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));
|
||||
$user->save();
|
||||
|
||||
$mailing->send_html("login_by_code.php", ['code' => $user->auth_code], [
|
||||
'address' => $email,
|
||||
'subject' => "Код авторизации",
|
||||
"from_name" => $_ENV['APP_NAME']
|
||||
]);
|
||||
}
|
||||
|
||||
$mailing = new Mailing();
|
||||
$mailing->send_html("login_by_code.php", ['code' => $code], [
|
||||
'address' => $email,
|
||||
'subject' => "Код авторизации",
|
||||
"from_name" => $_ENV['APP_NAME']
|
||||
]);
|
||||
|
||||
setcookie('user_email', $email, time()+60*15, '/', $_SERVER['SERVER_NAME'], false);
|
||||
|
||||
$this->cgView->render("enter_code.php", ['email' => $email]);
|
||||
}
|
||||
|
||||
|
@ -85,4 +85,15 @@ class UserService
|
||||
return $this->getByField("access_token", $token);
|
||||
}
|
||||
|
||||
public static function createUserByEmailAndPassword(string $email, string $password): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
$user->username = $email;
|
||||
$user->password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||||
$user->auth_code = mt_rand(100000, 999999);
|
||||
$user->auth_code_expires_at = date("Y-m-d H:i:s", strtotime("+5 minutes"));
|
||||
$user->save();
|
||||
}
|
||||
|
||||
}
|
15
kernel/views/mailing/register_by_code.php
Normal file
15
kernel/views/mailing/register_by_code.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* @var int $code
|
||||
* @var string $password
|
||||
*/
|
||||
?>
|
||||
|
||||
<p>
|
||||
Код подтверждения: <?= $code ?> <br><br>
|
||||
Ваш пароль: <?= $password ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Если вы не запрашивали код, проигнорируйте данное письмо.
|
||||
</p>
|
Loading…
Reference in New Issue
Block a user