diff --git a/app/Controllers/Api/Register.php b/app/Controllers/Api/Register.php index 3416ae6..3940e4a 100644 --- a/app/Controllers/Api/Register.php +++ b/app/Controllers/Api/Register.php @@ -36,8 +36,8 @@ class Register $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; - if (!strcasecmp(DB::query('SELECT username FROM users WHERE (LOWER(username) LIKE :username)', array(':username' => '%' . $username . '%'))[0]['username'], $username) === false || !preg_match("#^[a-zA-Z0-9]+$#", $username)) { - if (Word::strlen(ltrim($username)) >= 5 && Word::strlen(ltrim($username)) <= 20 && Router::checkCurl($_SERVER['HTTP_HOST'] . '/' . $username) != 200) { + if (!strcasecmp(DB::query('SELECT username FROM users WHERE (LOWER(username) LIKE :username)', array(':username' => '%' . $username . '%'))[0]['username'], $username) === false || Router::checkCurl($_SERVER['HTTP_HOST'] . '/' . $username) != 200 ) { + if (Word::strlen(ltrim($username)) >= 5 && Word::strlen(ltrim($username)) <= 20 && !preg_match("#^[a-zA-Z0-9]+$#", $username)) { if (Word::strlen(ltrim($password)) >= 5 && Word::strlen(ltrim($password)) <= 120) { @@ -106,6 +106,7 @@ class Register echo json_encode( array( 'errorcode' => '2', + 'errortitle' => 'Пользователь с такой почтой уже существует!', 'error' => 1 ) ); @@ -115,6 +116,7 @@ class Register echo json_encode( array( 'errorcode' => '3', + 'errortitle' => 'Почта некорректного формата!', 'error' => 1 ) ); @@ -123,6 +125,7 @@ class Register echo json_encode( array( 'errorcode' => '4', + 'errortitle' => 'Пароль меньше 5 символов!', 'error' => 1 ) ); @@ -131,6 +134,7 @@ class Register echo json_encode( array( 'errorcode' => '5', + 'errortitle' => 'Никнейм некорректный!', 'error' => 1 ) ); @@ -139,6 +143,7 @@ class Register echo json_encode( array( 'errorcode' => '6', + 'errortitle' => 'Никнейм уже существует!!', 'error' => 1 ) ); diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index d0c6fbd..589d381 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -4,7 +4,7 @@ namespace App\Controllers; use \App\Services\{Router, Auth, DB, Json}; use \App\Controllers\ExceptionRegister; use \App\Core\Page; -use \App\Controllers\Api\Login; +use \App\Controllers\Api\{Login, Register}; class ApiController { @@ -12,5 +12,8 @@ class ApiController public static function login() { return new Login(); } + public static function register() { + return new Register(); + } } \ No newline at end of file diff --git a/app/Core/Routes.php b/app/Core/Routes.php index 593c1cd..a75f9ee 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -16,7 +16,7 @@ class Routes Router::get('/register', 'RegisterController@i'); Router::get('/photo/$id', 'PhotoController@i'); Router::post('/api/login', 'ApiController@login'); - + Router::post('/api/register', 'ApiController@register'); diff --git a/views/pages/Register.php b/views/pages/Register.php index 6fd1864..1cf229b 100644 --- a/views/pages/Register.php +++ b/views/pages/Register.php @@ -56,18 +56,21 @@ if (!email.match(/^[0-9a-z_\-.]+@[0-9a-z_\-^.]+\.[a-z]{2,4}$/i)) err_email.html('Некорректный адрес'); - if (err_email.html() == '' && captchaPassed) { + if (err_email.html() == '') { $(this).prop('disabled', true).val('Отправка данных...'); - $.get('/api/register', { + $.post('/api/register', { username: username, email: email, password: password }, function(r) { - if (r != 0) { - $('#err_email').html(r == 1 ? 'Пользователь с таким e-mail уже зарегистрирован' : 'На этот адрес уже было отправлено письмо со ссылкой для подтверждения.

Проверьте, не попало ли оно в папку "Спам"!'); + r = JSON.parse(r); + if (r.errorcode > 0) { + $('#err_email').html(r.errortitle); $('#regbtn').prop('disabled', false).val('Зарегистрироваться'); - } else $('#form').submit(); + } else { + window.location.href = "/" + } }) .fail(function(jx) { if (jx.responseText != '') alert(jx.responseText);