49 lines
1.0 KiB
PHP
49 lines
1.0 KiB
PHP
<?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 = isset($_GET['uid']) ? $_GET['uid'] : '';
|
|
$db = new Database();
|
|
|
|
if(preg_match(PATTERN, $name) != 1) {
|
|
$error = 14101;
|
|
} else if($uid == '') {
|
|
$error = 14102;
|
|
} else if(
|
|
$db->query(
|
|
'SELECT EXISTS (
|
|
SELECT 1
|
|
FROM "Users"
|
|
WHERE "ID" = $1
|
|
)',
|
|
array($uid)
|
|
)['data'][0]['exists'] == 'f'
|
|
) {
|
|
$error = 14104;
|
|
} else {
|
|
$db->query(
|
|
'UPDATE "Users"
|
|
SET "name" = $1
|
|
WHERE "ID" = $2',
|
|
array($name, $uid)
|
|
);
|
|
if(preg_match('/violates unique constraint "Users_name_unique"/', pg_last_error()) == 1) {
|
|
$error = 14103;
|
|
} else {
|
|
$data = array('uid' => $uid, 'name' => $name);
|
|
}
|
|
}
|
|
|
|
$response = Database::create_response($data, $error);
|
|
print $response;
|
|
|
|
?>
|