battles/user_anketa.php

52 lines
2.1 KiB
PHP
Raw Normal View History

<?php
use Battles\Template;
use Battles\User;
2018-01-28 16:40:49 +00:00
session_start();
require_once 'functions.php';
2018-03-04 01:14:13 +00:00
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
2018-03-02 15:31:43 +00:00
$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);
2018-03-04 01:14:13 +00:00
$hobbie = filter_input(INPUT_POST, 'hobbie', FILTER_SANITIZE_STRING);
2018-03-02 17:23:17 +00:00
$hobbie = str_replace("\\n", "<br />", $hobbie);
$hobbie = str_replace("\\r", "", $hobbie);
$hobbie = str_replace("&lt;br&nbsp;/&gt;", "<br />", $hobbie);
if ($name || $hobbie) {
if (strlen($hobbie) > User::INFO_CHAR_LIMIT) {
err('Максимальная длинна поля Хобби: ' . User::INFO_CHAR_LIMIT . ' символов!');
} else {
$values = ['realname' => $name, 'color' => $color, 'info' => $hobbie];
db::c()->query('UPDATE users SET ?As WHERE id = ?i', $values, $user->getId());
}
2018-01-28 16:40:49 +00:00
}
2018-03-02 15:31:43 +00:00
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('Неверный текущий пароль!');
}
2018-03-02 15:31:43 +00:00
}
Template::header('Анкета');
2018-01-28 16:40:49 +00:00
?>
<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>
2018-03-02 15:31:43 +00:00
<h1>Безопасность</h1>
<form method="post">
2018-03-02 15:31:43 +00:00
<input placeholder="Старый пароль" name="oldpsw">
<input placeholder="Новый пароль" name="newpsw">
<input type="submit">
</form>