mirror of
https://github.com/claradex/nativegallery.git
synced 2024-12-22 16:41:04 +03:00
just register
This commit is contained in:
parent
0b42a6731c
commit
c69709ee79
4 changed files with 20 additions and 9 deletions
|
@ -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
|
||||
)
|
||||
);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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');
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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 уже зарегистрирован' : 'На этот адрес уже было отправлено письмо со ссылкой для подтверждения.<br /><br />Проверьте, не попало ли оно в папку "Спам"!');
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue