-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_edit_exec.php
83 lines (78 loc) · 2.3 KB
/
user_edit_exec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
session_start();
session_regenerate_id(true);
require_once __DIR__ . '/lib/common.php';
require_once __DIR__ . '/lib/db.php';
require_once __DIR__ . '/lib/session.php';
// ログイン済みかチェックする
if (!isUserLogin()) {
noLoginHTML('user_login.php');
exit();
}
// 変数定義
$userId = COMMON_INVALID_ID;
$userName = COMMON_INVALID_NAME;
$password = COMMON_INVALID_PASSWORD;
$winCount = 0;
$lossCount = 0;
$resetCount = false;
$html = '';
// POSTデータを取得する
$post = h($_POST);
// csrfトークンのチェック
if (!isset($post['csrf_token']) ||
!compareSessionCsrfToken($post['csrf_token'])) {
// csrfトークンエラー
csrfTokenErrorHTML('.');
exit();
} else {
// csrfトークンを削除する
deleteSessionCsrfToken();
}
// 設定されていれば上書きする
if (isset($post['user_id']) && is_numeric($post['user_id'])) {
$userId = intval($post['user_id']);
}
if (isset($post['name']) && isValidName($post['name'])) {
$userName = $post['name'];
}
if (isset($post['password']) && isHashedPassword($post['password'])) {
$password = $post['password'];
}
if (isset($post['reset_count']) && is_numeric($post['reset_count'])) {
$resetCount = ($post['reset_count']) ? true : false;
}
if ($userId == COMMON_INVALID_ID ||
$userName == COMMON_INVALID_NAME ||
$password == COMMON_INVALID_PASSWORD) {
// 各パラメータが設定されていない場合
$html = '修正に失敗しました。<br>';
} else {
if ($resetCount) {
// ユーザ名とパスワードに加え、各種カウンタ値も修正する
$result = dbEditUserResultData($userId, $userName, $password,
$winCount, $lossCount);
} else {
// ユーザ名とパスワードのみ修正する
$result = dbEditUserData($userId, $userName, $password);
}
if ($result) {
$html = '修正しました。<br>';
} else {
$html = '修正に失敗しました。<br>';
}
}
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ユーザ修正実行</title>
</head>
<body>
<?= $html ?>
<br>
<a href="user_menu.php">ユーザメニューへ</a>
</body>
</html>