diff --git a/app/Controllers/Api/Register.php b/app/Controllers/Api/Register.php new file mode 100644 index 0000000..3416ae6 --- /dev/null +++ b/app/Controllers/Api/Register.php @@ -0,0 +1,148 @@ + '%' . $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 (Word::strlen(ltrim($password)) >= 5 && Word::strlen(ltrim($password)) <= 120) { + + if (filter_var($email, FILTER_VALIDATE_EMAIL)) { + + + if (!DB::query('SELECT email FROM users WHERE email=:email', array(':email' => $email))) { + + + + $content = Json::return( + array( + 'route' => 'NONE', + 'regdate' => time() + ) + ); + + DB::query('INSERT INTO users VALUES (\'0\', :username, :email, :password 5, :content)', array(':username' => ltrim($username), ':password' => password_hash(ltrim($password), PASSWORD_BCRYPT), ':email' => $email, ':content' => $content)); + $cstrong = True; + $token = GenerateRandomStr::gen_uuid(); + $user_id = DB::query('SELECT id FROM users WHERE username=:username', array(':username' => $username))[0]['id']; + + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { + $ip = $_SERVER['HTTP_CLIENT_IP']; + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } else { + $ip = $_SERVER['REMOTE_ADDR']; + } + + $parser = new UserAgentParser(); + + $ua = $parser->parse(); + $ua = $parser(); + + $servicekey = GenerateRandomStr::gen_uuid(); + $url = 'http://ip-api.com/json/'.$ip; + + $response = file_get_contents($url); + + $data = json_decode($response, true); + $loc = $data['country'].', '.$data['city']; + DB::query('INSERT INTO login_tokens VALUES (\'0\', :token, :user_id, :platform, :browser, :browserversion, 0, :ip, :servicekey, :loc)', array( + ':token' => $token, + ':user_id' => $user_id, + ':platform' => $ua->platform(), + ':browser' => $ua->browser(), + ':browserversion' => $ua->browserVersion(), + ':ip' => $ip, + ':servicekey' => $servicekey, + ':loc' => $loc + )); + + setcookie("NGALLERYSESS", $token, time() + 120 * 180 * 240 * 720, '/', NULL, NULL, TRUE); + setcookie("NGALLERYSESS_", '1', time() + 120 * 180 * 240 * 360, '/', NULL, NULL, TRUE); + setcookie("NGALLERYID", $user_id, time() + 10 * 10 * 24 * 72, '/', NULL, NULL, TRUE); + + echo json_encode( + array( + 'errorcode' => '0', + 'error' => 0 + ) + ); + } else { + echo json_encode( + array( + 'errorcode' => '2', + 'error' => 1 + ) + ); + } + + } else { + echo json_encode( + array( + 'errorcode' => '3', + 'error' => 1 + ) + ); + } + } else { + echo json_encode( + array( + 'errorcode' => '4', + 'error' => 1 + ) + ); + } + } else { + echo json_encode( + array( + 'errorcode' => '5', + 'error' => 1 + ) + ); + } + } else { + echo json_encode( + array( + 'errorcode' => '6', + 'error' => 1 + ) + ); + } + unlink($lockFile); + } +} diff --git a/app/Controllers/RegisterController.php b/app/Controllers/RegisterController.php new file mode 100644 index 0000000..cf67a8d --- /dev/null +++ b/app/Controllers/RegisterController.php @@ -0,0 +1,18 @@ + - + diff --git a/views/pages/Login.php b/views/pages/Login.php index c49bf48..231db1e 100644 --- a/views/pages/Login.php +++ b/views/pages/Login.php @@ -34,8 +34,7 @@ -
Регистрация
-
Забыли пароль?
+
Регистрация

+ + + + + + + + + + + + + + \ No newline at end of file