forked from opentibiabr/myaac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.php
110 lines (95 loc) · 2.41 KB
/
validate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/**
* Ajax validator
* Returns json with result
*
* @package MyAAC
* @author Slawkens <[email protected]>
* @author OpenTibiaBR
* @copyright 2023 MyAAC
* @link https://github.com/opentibiabr/myaac
*/
// 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)
$_account->find($account);
else
$_account->load($account);
if($_account->isLoaded())
error_('Account with this name already exist.');
success_('Good account' . (USE_ACCOUNT_NAME ? ' name' : '') . ' ( ' . $account . ' ).');
}
else if(isset($_GET['email']))
{
$email = $_GET['email'];
if(!Validator::email($email))
error_(Validator::getLastError());
if($config['account_mail_unique'])
{
$account = new OTS_Account();
$account->findByEMail($email);
if($account->isLoaded())
error_('Account with this e-mail already exist.');
}
success_(1);
}
else if(isset($_GET['name']))
{
$name = strtolower(stripslashes($_GET['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>' . 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();
}