T201704041211
This commit is contained in:
@@ -20,3 +20,7 @@
|
|||||||
13102 - No valid time specified
|
13102 - No valid time specified
|
||||||
13103 - No chosen answer specified
|
13103 - No chosen answer specified
|
||||||
13104 - No game for specified user
|
13104 - No game for specified user
|
||||||
|
|
||||||
|
= rename.php =
|
||||||
|
14101 - User name doesn't match rules
|
||||||
|
14102 - User name already exists
|
||||||
|
|||||||
@@ -56,9 +56,9 @@ class Database
|
|||||||
return 'Success.';
|
return 'Success.';
|
||||||
case 10101:
|
case 10101:
|
||||||
return 'SQL statement did not give a result.';
|
return 'SQL statement did not give a result.';
|
||||||
case 11101:
|
case 11101 || 14101:
|
||||||
return 'User name does not match rules. User name must be 6 to 20 characters and consist of English letters and numbers only.';
|
return 'User name does not match rules. User name must be 6 to 20 characters and consist of English letters and numbers only.';
|
||||||
case 11102:
|
case 11102 || 14102:
|
||||||
return 'User name already exists. Please pick a different name.';
|
return 'User name already exists. Please pick a different name.';
|
||||||
case 12101 || 13101:
|
case 12101 || 13101:
|
||||||
return 'User ID not specified. This is an internal error.';
|
return 'User ID not specified. This is an internal error.';
|
||||||
|
|||||||
32
rename.php
Normal file
32
rename.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: leanderschmedemann
|
||||||
|
* Date: 04/04/2017
|
||||||
|
* Time: 12:07
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once('includes.inc.php');
|
||||||
|
define('PATTERN', '/^[a-zA-Z0-9 ]{6,20}$/');
|
||||||
|
$data = '';
|
||||||
|
$error = 0;
|
||||||
|
$name = isset($_GET['name']) ? $_GET['name'] : '';
|
||||||
|
$uid = md5(uniqid(rand(), true));
|
||||||
|
$db = new Database();
|
||||||
|
|
||||||
|
if(preg_match(PATTERN, $name) != 1) {
|
||||||
|
$error = 14101;
|
||||||
|
} else {
|
||||||
|
// Create user.
|
||||||
|
$db->query('UPDATE "Users" SET "name" = $1 WHERE "ID" = $2', array($name, $uid));
|
||||||
|
// Create error if user to create already exists.
|
||||||
|
if(preg_match('/violates unique constraint "Users_name_unique"/', pg_last_error()) == 1) {
|
||||||
|
$error = 14102;
|
||||||
|
} else {
|
||||||
|
$data = array('uid' => $uid, 'name' => $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$response = Database::create_response($data, $error);
|
||||||
|
print $response;
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user