added option for resetting account

This commit is contained in:
printempw 2016-02-10 21:21:15 +08:00
parent 15b9715aef
commit b43b19abe4
6 changed files with 96 additions and 23 deletions

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-01-16 23:01:33 * @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-08 22:11:17 * @Last Modified time: 2016-02-10 21:00:40
* *
* - login, register, logout * - login, register, logout
* - upload, change, delete * - upload, change, delete
@ -229,6 +229,22 @@ if ($action == "change") {
$json['errno'] = 1; $json['errno'] = 1;
$json['msg'] = "无效的 token请先登录。"; $json['msg'] = "无效的 token请先登录。";
} }
} else if ($action == "reset") {
if (isset($_SESSION['token']) && $_SESSION['token'] == $user->getToken()) {
if (checkPost()) {
if ($user->checkPasswd($_POST['passwd'])) {
$user->reset();
$json['errno'] = 0;
$json['msg'] = "重置成功。";
} else {
$json['errno'] = 1;
$json['msg'] = "错误的密码。";
}
}
} else {
$json['errno'] = 1;
$json['msg'] = "无效的 token请先登录。";
}
} else if ($action == "logout") { } else if ($action == "logout") {
if (Utils::getValue('token', $_SESSION)) { if (Utils::getValue('token', $_SESSION)) {
session_destroy(); session_destroy();

View File

@ -2,7 +2,7 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-01-21 07:57:38 * @Date: 2016-01-21 07:57:38
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-10 14:16:23 * @Last Modified time: 2016-02-10 20:32:32
*/ */
@import url(https://fonts.googleapis.com/css?family=Ubuntu); @import url(https://fonts.googleapis.com/css?family=Ubuntu);
@ -76,6 +76,10 @@ p {
background: rgb(202, 60, 60); background: rgb(202, 60, 60);
color: #fff; color: #fff;
} }
.pure-button-warning {
background: #ec971f;
color: #fff;
}
.container { .container {
width: 100%; width: 100%;
height: 100%; height: 100%;
@ -122,12 +126,6 @@ p {
} }
.panel-default {
border-color: #ddd!important;
}
.panel-danger {
border-color: #ebccd1!important;
}
.panel { .panel {
background-color: #fff; background-color: #fff;
border: 1px solid transparent; border: 1px solid transparent;
@ -137,15 +135,31 @@ p {
width: 90%; width: 90%;
margin: 0 auto 20px; margin: 0 auto 20px;
} }
.panel-danger>.panel-heading {
.panel-default {
border-color: #ddd!important;
}
.panel-danger {
border-color: #ebccd1!important;
}
.panel-warning {
border-color: #faebcc;
}
.panel-default > .panel-heading {
color: #333;
background-color: #f5f5f5;
border-color: #ddd;
}
.panel-danger > .panel-heading {
color: #a94442; color: #a94442;
background-color: #f2dede; background-color: #f2dede;
border-color: #ebccd1; border-color: #ebccd1;
} }
.panel-default>.panel-heading { .panel-warning > .panel-heading {
color: #333; color: #8a6d3b;
background-color: #f5f5f5; background-color: #fcf8e3;
border-color: #ddd; border-color: #faebcc;
} }
.panel-heading { .panel-heading {
padding: 10px 15px; padding: 10px 15px;

View File

@ -2,7 +2,7 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-02-03 17:21:46 * @Date: 2016-02-03 17:21:46
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-05 21:23:08 * @Last Modified time: 2016-02-10 20:53:55
*/ */
'use strict'; 'use strict';
@ -79,3 +79,25 @@ $('#delete').click(function(){
}); });
}); });
}); });
$('#reset').click(function(){
Ply.dialog("prompt", {
title: "这是危险操作!输入密码来确认:",
form: { passwd: "Password" }
}).done(function(ui){
var passwd = ui.data.passwd;
$.ajax({
type: "POST",
url: "../ajax.php?action=reset",
dataType: "json",
data: { "uname": docCookies.getItem('uname'), "passwd": passwd },
success: function(json) {
if (json.errno == 0) {
showAlert(json.msg);
} else {
showAlert(json.msg);
}
}
});
});
});

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-01-16 23:01:33 * @Date: 2016-01-16 23:01:33
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-10 15:07:08 * @Last Modified time: 2016-02-10 21:04:32
*/ */
class User class User
@ -76,9 +76,23 @@ class User
return $this->db->delete($this->uname); return $this->db->delete($this->uname);
} }
public function reset() {
for ($i = 1; $i <= 3; $i++) {
switch($i) {
case 1: $type = "steve"; break;
case 2: $type = "alex"; break;
case 3: $type = "cape"; break;
}
if ($this->getTexture($type) != "")
Utils::remove("./textures/".$this->getTexture($type));
$this->db->update($this->uname, 'hash_'.$type, '');
}
$this->db->update($this->uname, 'preference', 'default');
}
/** /**
* Get textures of user * Get textures of user
* @param string $type steve|alex|cape * @param string $type steve|alex|cape, 'skin' for texture of preferred model
* @return string sha256-hash of texture file * @return string sha256-hash of texture file
*/ */
public function getTexture($type) { public function getTexture($type) {

View File

@ -3,14 +3,14 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-02-04 19:37:21 * @Date: 2016-02-04 19:37:21
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-10 18:37:35 * @Last Modified time: 2016-02-10 21:12:26
*/ */
?> ?>
<div id="skinpreview"> <div id="skinpreview">
<div id="preview-2d"> <div id="preview-2d">
<p>Steve 模型的皮肤:<img id="steve" class="skin2d" src="<?php echo "../textures/".$user->getTexture('skin');?>" /></p> <p>Steve 模型的皮肤:<img id="steve" class="skin2d" src="<?php if ($t = $user->getTexture('steve')) echo "../textures/".$t;?>" /></p>
<p>Alex 模型的皮肤:<img id="alex" class="skin2d" src="<?php echo "../textures/".$user->getTexture('alex');?>" /></p> <p>Alex 模型的皮肤:<img id="alex" class="skin2d" src="<?php if ($t = $user->getTexture('alex')) echo "../textures/".$t;?>" /></p>
<p>披风:<img id="cape" class="skin2d" src="<?php echo "../textures/".$user->getTexture('cape');?>" /></p> <p>披风:<img id="cape" class="skin2d" src="<?php if ($t = $user->getTexture('cape')) echo "../textures/".$t;?>" /></p>
</div> </div>
</div> </div>

View File

@ -3,7 +3,7 @@
* @Author: prpr * @Author: prpr
* @Date: 2016-02-03 16:12:45 * @Date: 2016-02-03 16:12:45
* @Last Modified by: prpr * @Last Modified by: prpr
* @Last Modified time: 2016-02-10 14:39:11 * @Last Modified time: 2016-02-10 20:54:13
*/ */
require "../includes/session.inc.php"; require "../includes/session.inc.php";
?> ?>
@ -77,16 +77,23 @@ require "../includes/session.inc.php";
</div> </div>
</div> </div>
</div> </div>
<?php if ($user->is_admin): ?>
<div class="pure-u-1 pure-u-md-1-2"> <div class="pure-u-1 pure-u-md-1-2">
<div class="panel panel-warning">
<div class="panel-heading">重置账号</div>
<div class="panel-body">
<p>这将会删除所有你上传的内容。我们不提供任何备份,确定?</p>
<button id="reset" class="pure-button pure-button-warning">重置我的账户</button>
</div>
</div>
<?php if ($user->is_admin): ?>
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">欢迎,尊敬的管理员</div> <div class="panel-heading">欢迎,尊敬的管理员</div>
<div class="panel-body"> <div class="panel-body">
<p>在这里管理你的皮肤站: <a href="../admin/">仪表盘</a></p> <p>在这里管理你的皮肤站: <a href="../admin/">仪表盘</a></p>
</div> </div>
</div> </div>
</div>
<?php endif; ?> <?php endif; ?>
</div>
</div> </div>
</div> </div>