battles/user_anketa.php

75 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2018-01-28 16:40:49 +00:00
session_start();
if (!isset($_SESSION['uid'])) {
header('Location: /index.php');
die();
}
include_once('config.php');
include_once('functions.php');
if ($u->i()['battle'] > 0) {
header('Location: /fbattle.php');
die();
}
2018-03-02 15:31:43 +00:00
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);
$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-02 17:23:17 +00:00
$hobbie = filter_input(INPUT_POST, 'hobbie', FILTER_SANITIZE_SPECIAL_CHARS);
$hobbie = str_replace("\\n", "<br />", $hobbie);
$hobbie = str_replace("\\r", "", $hobbie);
$hobbie = str_replace("&lt;br&nbsp;/&gt;", "<br />", $hobbie);
if ($name || $color || $hobbie) {
2018-01-28 16:40:49 +00:00
$simbolcount = strlen($hobbie);
switch ($color) {
case 1: $color = 'blue'; break;
case 2: $color = 'green'; break;
default: $color = 'black'; break;
}
2018-01-28 16:40:49 +00:00
if ($simbolcount > 1500) {
err('Максимальная длинна поля Хобби: 1500 символов!');
} else {
db::c()->query('UPDATE `users` SET `realname` = "?s", `color` = "?s", `info` = "?s" WHERE `id` = ?i', $name, $color, $hobbie, $u->i()['id']);
}
2018-01-28 16:40:49 +00:00
}
2018-03-02 15:31:43 +00:00
if ($oldpsw && $newpsw){
2018-03-02 17:23:17 +00:00
if (password_verify($oldpsw, $u->i()['pass'])){
2018-03-02 15:31:43 +00:00
db::c()->query('UPDATE `users` SET `pass` = "?s" WHERE `id` = ?i', password_hash($newpsw,PASSWORD_DEFAULT), $u->i()['id']);
} else err('Неверный текущий пароль!');
}
2018-01-28 16:40:49 +00:00
?>
<!doctype html>
2018-01-28 16:40:49 +00:00
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="css/main.css">
<title>Анкета</title>
</head>
<body>
<a href="main.php"> на главную</a>
<h1>Анкета персонажа <?= $u->i()['login'] ?></h1>
<form method="post" action="user_anketa.php">
<input name="name" placeholder="Реальное имя" value="<?= $u->i()['realname']; ?>"><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="Хобби"><?= $u->i()['info'] ?></textarea><br>
<input name="submit" type="submit">
</form>
2018-03-02 15:31:43 +00:00
<h1>Безопасность</h1>
<form method="post" action="user_anketa.php">
<input placeholder="Старый пароль" name="oldpsw">
<input placeholder="Новый пароль" name="newpsw">
<input type="submit">
</form>
</body>
2018-01-28 16:40:49 +00:00
</html>