myaac/tools/validate.php
Gabriel Pedro a692607c5e
feat: replace POT Query Builder to Eloquent ORM (#230)
* wip

* wip

* wip

* wip

* wip

* fix: reusing pdo connection from pot

* wip

* wip

* wip

* wip

* move files

In future, all classes will be in src/ folder

* Replace namespace name, for future

* Remove duplicated exception

* Fix towns from db

* Fix spells page

* Add default FAQ question + FAQ model

* feat: reset colors in menus

* Add confirm + save button at the top (menus)

* Do not insert duplicated FAQ on install

* Refactor install menus

* Fix changelogs showing

* Fix menu update, only with specified template name

* Fix account create -> missing compat

* Fix bans_per_page

* banned_by is player_id. type = 2 is namelock in tfs 0.3

* Add getPlayerNameById, fix getPlayerNameByAccount

* Change link name

* Order by lastlogin

* fix: query optimize

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Refactor notepad.php, class was useless

* This is showing error, if the updated rows = 0

* Fix success & error class (bootstrap)

* Uncomment require migrate.php

* Some distro have owner_id

* Update Player.php

---------

Co-authored-by: slawkens <slawkens@gmail.com>
2023-08-21 10:16:58 +02:00

114 lines
2.4 KiB
PHP

<?php
/**
* Ajax validator
* Returns json with result
*
* @package MyAAC
* @author Slawkens <slawkens@gmail.com>
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Account;
// we need some functions
require '../common.php';
require SYSTEM . 'functions.php';
require SYSTEM . 'init.php';
require SYSTEM . 'login.php';
$error = '';
if(isset($_GET['account']))
{
$account = $_GET['account'];
if(USE_ACCOUNT_NAME) {
if(!Validator::accountName($account))
error_(Validator::getLastError());
}
else if(!Validator::accountId($account))
error_(Validator::getLastError());
$_account = new OTS_Account();
if(USE_ACCOUNT_NAME || USE_ACCOUNT_NUMBER)
$_account->find($account);
else
$_account->load($account);
$accountNameOrNumber = (USE_ACCOUNT_NAME ? ' name' : 'number');
if($_account->isLoaded())
error_("Account with this $accountNameOrNumber already exist.");
success_("Good account $accountNameOrNumber ($account).");
}
else if(isset($_GET['email']))
{
$email = $_GET['email'];
if(!Validator::email($email))
error_(Validator::getLastError());
if($config['account_mail_unique'])
{
if(Account::where('email', '=', $email)->exists())
error_('Account with this e-mail already exist.');
}
success_(1);
}
else if(isset($_GET['name']))
{
$name = $_GET['name'];
if(!admin()) {
$name = strtolower(stripslashes($name));
}
if(!Validator::characterName($name))
error_(Validator::getLastError());
if(!admin() && !Validator::newCharacterName($name))
error_(Validator::getLastError());
require_once LIBS . 'CreateCharacter.php';
$createCharacter = new CreateCharacter();
if (!$createCharacter->checkName($name, $errors)) {
error_($errors['name']);
}
success_('Good. Your name will be:<br /><b>' . (admin() ? $name : ucwords($name)) . '</b>');
}
else if(isset($_GET['password']) && isset($_GET['password2'])) {
$password = $_GET['password'];
$password2 = $_GET['password2'];
if(!isset($password[0])) {
error_('Please enter the password for your new account.');
}
if(!Validator::password($password))
error_(Validator::getLastError());
if($password != $password2)
error_('Passwords are not the same.');
success_(1);
}
else
error_('Error: no input specified.');
/**
* Output message & exit.
*
* @param string $desc Description
*/
function success_($desc) {
echo json_encode(array(
'success' => $desc
));
exit();
}
function error_($desc) {
echo json_encode(array(
'error' => $desc
));
exit();
}