64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
|
|
use Battles\Template;
|
|
|
|
session_start();
|
|
require_once 'functions.php';
|
|
define('INFO_CHAR_LIMIT', 1500);
|
|
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
|
|
$oldpsw = filter_input(INPUT_POST, 'oldpsw', FILTER_SANITIZE_SPECIAL_CHARS);
|
|
$newpsw = filter_input(INPUT_POST, 'newpsw', FILTER_SANITIZE_SPECIAL_CHARS);
|
|
$color = filter_input(INPUT_POST, 'color', FILTER_VALIDATE_INT);
|
|
$hobbie = filter_input(INPUT_POST, 'hobbie', FILTER_SANITIZE_STRING);
|
|
$hobbie = str_replace("\\n", "<br />", $hobbie);
|
|
$hobbie = str_replace("\\r", "", $hobbie);
|
|
$hobbie = str_replace("<br />", "<br />", $hobbie);
|
|
|
|
if ($name || $color || $hobbie) {
|
|
switch ($color) {
|
|
case 1:
|
|
$color = 'blue';
|
|
break;
|
|
case 2:
|
|
$color = 'green';
|
|
break;
|
|
default:
|
|
$color = 'black';
|
|
break;
|
|
}
|
|
|
|
if (strlen($hobbie) > INFO_CHAR_LIMIT) {
|
|
err('Максимальная длинна поля Хобби: ' . INFO_CHAR_LIMIT . ' символов!');
|
|
} else {
|
|
$values = ['realname' => $name, 'color' => $color, 'info' => $hobbie];
|
|
db::c()->query('UPDATE users SET ?As WHERE id = ?i', $values, $user->getId());
|
|
}
|
|
}
|
|
|
|
if ($oldpsw && $newpsw) {
|
|
if (password_verify($oldpsw, $user->getPass())) {
|
|
db::c()->query('UPDATE `users` SET `pass` = "?s" WHERE `id` = ?i', password_hash($newpsw, PASSWORD_DEFAULT), $user->getId());
|
|
} else {
|
|
err('Неверный текущий пароль!');
|
|
}
|
|
}
|
|
Template::header('Анкета');
|
|
?>
|
|
<a href="main.php">← на главную</a>
|
|
<h1>Анкета персонажа <?= $user->getLogin() ?></h1>
|
|
<form method="post">
|
|
<input name="name" placeholder="Реальное имя" value="<?= $user->getRealname() ?>"><br>
|
|
<select name="color" id="color">
|
|
<option value="0" selected>Чёрный</option>
|
|
<option value="1">Синий</option>
|
|
<option value="2">Зелёный</option>
|
|
</select><label for="color"></label><br>
|
|
<textarea name="hobbie" placeholder="Хобби"><?= $user->getInfo() ?></textarea><br>
|
|
<input name="submit" type="submit">
|
|
</form>
|
|
<h1>Безопасность</h1>
|
|
<form method="post">
|
|
<input placeholder="Старый пароль" name="oldpsw">
|
|
<input placeholder="Новый пароль" name="newpsw">
|
|
<input type="submit">
|
|
</form>
|