2022-12-11 13:55:49 +05:00
|
|
|
<?php
|
|
|
|
|
2023-02-21 22:42:21 +05:00
|
|
|
switch( @$_POST['act'] ) {
|
2022-12-11 13:55:49 +05:00
|
|
|
//Проверка существования email
|
|
|
|
case 'checkEmail':
|
2023-02-21 22:42:21 +05:00
|
|
|
echo ( \DB::getValue( "SELECT `id` FROM `users` WHERE `email`=?", $_POST['email'] ) ) ? 3 : 0;
|
2022-12-11 13:55:49 +05:00
|
|
|
break;
|
|
|
|
|
2023-02-21 21:04:58 +05:00
|
|
|
// Регистрация пользователя
|
|
|
|
case 'reg':
|
|
|
|
$err=0;
|
|
|
|
// Сверяем капчу
|
2023-02-28 21:22:24 +05:00
|
|
|
if ( !$_SESSION['capcha'] ){
|
|
|
|
header( 'HTTP/1.1 403 Capcha' );
|
|
|
|
die( "Нехрен взламывать капчу" );
|
|
|
|
}
|
2023-02-21 22:42:21 +05:00
|
|
|
$err = ( $_POST['capcha'] != $_SESSION['capcha'] ) ? 1 : $err;
|
2023-02-21 21:04:58 +05:00
|
|
|
// Сверяем пароли
|
2023-02-21 22:42:21 +05:00
|
|
|
$err = ( $_POST['pwd'] != $_POST['pwd2'] ) ? 2 : $err;
|
2023-02-21 21:04:58 +05:00
|
|
|
//проверяем ввели ли электронку
|
2023-02-23 22:13:18 +05:00
|
|
|
$err = ( !$_POST['email'] ) ? 4 : $err;
|
2023-02-21 21:04:58 +05:00
|
|
|
// Проверяем наличие юзера в БД
|
2023-02-23 22:13:18 +05:00
|
|
|
$err = ( \DB::getValue( "SELECT `id` FROM `users` WHERE `email`=?", $_POST['email'] ) ) ? 3 : $err;
|
2023-02-21 22:42:21 +05:00
|
|
|
if ( $err==0 ){
|
|
|
|
$count_users = \DB::getAll( "SELECT COUNT(*) FROM `users`" );
|
|
|
|
$dostup = ( $count_users[0]['COUNT(*)']==0 ) ? 'a' : 'u'; //проверяем есть ли хоть один юзер в базе, если нет, создаем первого админом
|
|
|
|
$_SESSION['user_id'] = \DB::add ( "INSERT INTO `users` (`email`, `pwd`, `act`, `dostup`) VALUES (?, ?, ?, ?)", array( $_POST['email'], md5( $_POST['pwd'] ), 1, $dostup ) );
|
|
|
|
$_SESSION['dostup'] = $dostup;
|
2022-12-11 13:55:49 +05:00
|
|
|
}
|
2023-02-21 21:04:58 +05:00
|
|
|
echo $err;
|
|
|
|
break;
|
|
|
|
default:
|
2022-12-11 13:55:49 +05:00
|
|
|
}
|
|
|
|
?>
|