Skip to content

Commit

Permalink
修复大多数遗留问题
Browse files Browse the repository at this point in the history
1. 邀请码 新增 *
2. 邀请码 修改 *
3. 邀请码 删除 *
4. 用户修改
5. 用户删除
6. 其他遗留问题
  • Loading branch information
sendya committed Mar 17, 2016
1 parent c404bcc commit f68a393
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 116 deletions.
86 changes: 60 additions & 26 deletions Library/Controller/Admin/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,44 @@ public function inviteList() {
//throw new \Core\Error("user list", 505);
global $user;

$inviteList = InviteModel::GetInviteArray();
$inviteList = InviteModel::GetInviteArray(0);

include Template::load('/admin/invite');
}

public function inviteOldList() {
global $user;

$inviteList = InviteModel::GetInviteArray(1);
include Template::load('/admin/invite');
}

/**
* 添加一个邀请码
*/
public function add() {
global $user;
$result = array('error'=> 0, 'message'=> '添加成功');
$plan = 'A';
$inviteNumber = 1;
if($_POST['plan'] != null) {
$plan = $_POST['plan'];
}
if($_POST['number'] != null) {
$inviteNumber = $_POST['number'];
}
if($inviteNumber > 1) {
for($i=0; $i<$inviteNumber;$i++){
InviteModel::addInvite($user->uid, $plan);
}
} else {
InviteModel::addInvite(-1, 'A');
}
$result['inviteNumber'] = $inviteNumber;
$result['plan'] = $plan;
echo json_encode($result);
exit();
global $user;
$result = array('error'=> 0, 'message'=> '添加成功,刷新可见');
$plan = 'A';
$inviteNumber = 1;
if($_POST['plan'] != null) {
$plan = $_POST['plan'];
}
if($_POST['number'] != null) {
$inviteNumber = $_POST['number'];
}
if($inviteNumber > 1) {
for($i=0; $i<$inviteNumber;$i++){
InviteModel::addInvite($user->uid, $plan);
}
} else {
InviteModel::addInvite(-1, $plan);
}
$result['inviteNumber'] = $inviteNumber;
$result['plan'] = $plan;

echo json_encode($result);
exit();
}

public function delete() {
Expand All @@ -68,12 +69,45 @@ public function delete() {
$result = array('error'=> 0, 'message'=> '删除成功');
}

echo json_encode($result);
exit();
echo json_encode($result);
exit();
}

public function query() {
global $user;
$result = array('error'=> -1, 'message'=> 'Request failed');

if($_POST['invite'] != null) {
$invite = InviteModel::GetInviteByInviteCode(trim($_POST['invite']));
if($invite != null) {
$result = array('error'=> 0, 'message'=> 'success');
$invite->dateLine = date('Y-m-d', $invite->dateLine);
$result['data'] = $invite;
}
}
echo json_encode($result);
exit();
}

public function update() {
// TODO --
global $user;
$result = array('error'=> -1, 'message'=> 'Request failed');

if($_POST['invite'] != null) {
$invite = InviteModel::GetInviteByInviteCode(trim($_POST['invite']));
if($invite != null) {
$invite->dateLine = strtotime($_POST['add_time1'] + " " + $_POST['add_time2']);
$invite->expiration = $_POST['expiration'];
$invite->plan = $_POST['plan'];
$rs = $invite->updateInvite();
if($rs > 0) {
$result = array('error'=> 0, 'message'=> '更新邀请码成功');
}

}
}
echo json_encode($result);
exit();
}

}
37 changes: 32 additions & 5 deletions Library/Controller/Admin/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function delete() {
global $user;

$result = array("error" => 1, "message" => "Request failed");
if($_POST['uid'] != null) {
$rs = UserModel::delete($_POST['uid']);
if($_POST['userId'] != null) {
$rs = UserModel::delete($_POST['userId']);
if($rs) {
$result['error'] = 0;
$result['message'] = '删除账户成功!';
Expand Down Expand Up @@ -60,19 +60,46 @@ public function modify() {
global $user;

$result = array("error" => 1, "message" => "Request failed");
if($_POST['uid'] != null) {
$us = UserModel::GetUserByUserId($_POST['uid']);
if($_POST['user_uid'] != null) {
$us = UserModel::GetUserByUserId($_POST['user_uid']);
if($us) {
if($_POST['user_email'] != null) $us->email = $_POST['user_email'];
if($_POST['user_nickname'] != null) $us->nickname = $_POST['user_nickname'];
if($_POST['user_port'] != null) $us->port = $_POST['user_port'];
if($_POST['user_sspwd'] != null) $us->sspwd = $_POST['user_sspwd'];
if($_POST['user_plan'] != null) $us->plan = $_POST['user_plan'];
if($_POST['user_invite_num'] != null) $us->invite_num = $_POST['user_invite_num'];
if($_POST['user_transfer'] != null) $us->transfer = $_POST['user_transfer'] * Util::GetGB();
if($_POST['user_transfer'] != null) $us->transfer = floatval($_POST['user_transfer']) * Util::GetGB();
if($_POST['user_flow_up'] != null) $us->flow_up = $_POST['user_flow_up'] * Util::GetGB();
if($_POST['user_enable'] != null) $us->enable = $_POST['user_enable']; // 是否启用该用户。该字段会强制用户无法链接到所有服务器!
$result['user'] = $us;
if($us->enable != 0 && $us->enable != 1) $us->enable=0;
if($us->port!=null && $us->port!=0) {
$rs = UserModel::checkUserPortIsAvailable($us->port, $us->uid);
if($rs) {
$result = array("error" => 1, "message" => "端口{$rs->port}已被占用,请更换");
echo json_encode($result);
exit();
}
}
if(strlen($us->plan) > 4) {
$result = array("error" => 1, "message" => "账户等级最大字符4位");
echo json_encode($result);
exit();
}
if($_POST['user_password']!=null && $_POST['user_password']!='') { // change password
$us->savePassword(trim($_POST['user_password']));
}
$rs2 = $us->updateUser();
if($rs2) {
$result['error'] = 0;
$result['message'] = '更新信息成功';
} else {
$result['message'] = '出现未知错误,修改失败';
}
}
}
echo json_encode($result);
exit();
}
}
15 changes: 11 additions & 4 deletions Library/Model/Invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ public static function GetInviteByInviteCode($invite) {
return $statement->fetch(\PDO::FETCH_CLASS);
}

public static function GetInviteArray($plan = '') {
public static function GetInviteArray($status = -1) {
$sql = "SELECT * FROM invite";
if($status == 0) {
$sql .= " WHERE status = 0";
} else if($status == 1) {
$sql .= " WHERE status = 1 OR status = -1 ";
}
$statement = Database::prepare($sql);
$statement->execute();
$inviteList = $statement->fetchAll(\PDO::FETCH_CLASS, '\\Model\\Invite');
Expand Down Expand Up @@ -109,21 +114,23 @@ public function updateInvite() {
Database::beginTransaction();
}
$statement = Database::prepare("UPDATE invite SET expiration=:expiration,
`reguid`=:reguid, `regDateLine`=:regDateLine, `status`=:status, `inviteIp`=:inviteIp WHERE invite=:invite");
`reguid`=:reguid, `plan`=:plan, `regDateLine`=:regDateLine, `status`=:status, `inviteIp`=:inviteIp WHERE `invite`=:invite");
$statement->bindValue(':expiration', $this->expiration, \PDO::PARAM_INT);
$statement->bindValue(':reguid', $this->reguid, \PDO::PARAM_INT);
$statement->bindValue(':regDateLine', $this->regDateLine, \PDO::PARAM_INT);
$statement->bindValue(':status', $this->status, \PDO::PARAM_INT);
$statement->bindValue(':plan', $this->plan, \PDO::PARAM_STR);
$statement->bindValue(':inviteIp', $this->inviteIp, \PDO::PARAM_STR);
$statement->bindValue(':invite', $this->invite, \PDO::PARAM_STR);
$statement->execute();
$rs = $statement->execute();
if (!$inTransaction) {
Database::commit();
}
return $rs;
}

public static function addInvite($uid, $plan = 'A') {
$iv = $uid . substr(hash("sha256", $uid . Util::GetRandomChar(10)),0, 26);
$iv = substr(hash("sha256", $uid . Util::GetRandomChar(10)),0, 26) . $uid;
$invite = new Invite();
$invite->uid = $uid;
$invite->dateLine = time();
Expand Down
29 changes: 23 additions & 6 deletions Library/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ public function updateUser() {
if (!$inTransaction) {
Database::beginTransaction();
}
$statement = Database::prepare("UPDATE member SET email=:email, `password`=:pwd, sspwd=:sspwd, `port`=:port, nickname=:nickname,
`flow_up`=:flow_up, `flow_down`=:flow_down, transfer=:transfer, plan=:plan, `enable`=:enable, invite=:invite, regDateLine=:regDateLine,
lastConnTime=:lastConnTime,lastCheckinTime=:lastCheckinTime,lastFindPasswdTime=:lastFindPasswdTime,
lastFindPasswdCount=:lastFindPasswdCount,forgePwdCode=:forgePwdCode WHERE uid=:userId");
$sql = "UPDATE member SET email=:email, sspwd=:sspwd, `port`=:port, nickname=:nickname," .
"`flow_up`=:flow_up, `flow_down`=:flow_down, transfer=:transfer, plan=:plan, `enable`=:enable, invite=:invite, invite_num=:invite_num, regDateLine=:regDateLine,".
"lastConnTime=:lastConnTime,lastCheckinTime=:lastCheckinTime,lastFindPasswdTime=:lastFindPasswdTime,".
"lastFindPasswdCount=:lastFindPasswdCount,forgePwdCode=:forgePwdCode WHERE uid=:userId";

$statement = Database::prepare($sql);
$statement->bindValue(':email', $this->email, \PDO::PARAM_STR);
$statement->bindValue(':pwd', $this->password, \PDO::PARAM_STR);
$statement->bindValue(':sspwd', $this->sspwd, \PDO::PARAM_STR);
$statement->bindValue(':port', $this->port, \PDO::PARAM_INT);
$statement->bindValue(':nickname', $this->nickname, \PDO::PARAM_STR);
Expand All @@ -194,18 +195,22 @@ public function updateUser() {
$statement->bindValue(':transfer', $this->transfer, \PDO::PARAM_INT);
$statement->bindValue(':plan', $this->plan, \PDO::PARAM_STR);
$statement->bindValue(':enable', $this->enable, \PDO::PARAM_INT);
$statement->bindValue(':invite', $this->invite, \PDO::PARAM_INT);
$statement->bindValue(':invite', $this->invite, \PDO::PARAM_STR);
$statement->bindValue(':invite_num', $this->invite, \PDO::PARAM_INT);
$statement->bindValue(':regDateLine', $this->regDateLine, \PDO::PARAM_INT);
$statement->bindValue(':lastConnTime', $this->lastConnTime, \PDO::PARAM_INT);
$statement->bindValue(':lastCheckinTime', $this->lastCheckinTime, \PDO::PARAM_INT);
$statement->bindValue(':lastFindPasswdTime', $this->lastFindPasswordTime, \PDO::PARAM_INT);
$statement->bindValue(':lastFindPasswdCount', $this->lastFindPasswordCount, \PDO::PARAM_INT);
$statement->bindValue(':forgePwdCode', $this->forgePwdCode, \PDO::PARAM_STR);

$statement->bindValue(':userId', $this->uid, \PDO::PARAM_INT);

$flag = $statement->execute();
if (!$inTransaction) {
Database::commit();
}
return $flag;
}

/**
Expand All @@ -229,6 +234,18 @@ public static function delete($uid) {
}


public static function checkUserPortIsAvailable($port = 0, $uid) {
if($port != 0) {
$statement = Database::prepare("SELECT * FROM member WHERE port=? AND uid<>?");
$statement->bindValue(1, $port, \PDO::PARAM_INT);
$statement->bindValue(2, $uid, \PDO::PARAM_INT);
$statement->execute();
$statement->setFetchMode(\PDO::FETCH_CLASS, '\\Model\\User');
return $statement->fetch(\PDO::FETCH_CLASS);
}
}


/**
* Get password
*/
Expand Down
3 changes: 3 additions & 0 deletions Resource/Default/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ a {
a:hover {
color: #bdbebe;
}
.bootstrap-timepicker-widget.dropdown-menu.open{
z-index: 9999;
}
:not([class*="icon"]):not(i):not([class*="fxfont"]){font-family: "Microsoft YaHei" !important}
7 changes: 5 additions & 2 deletions Template/Default/admin/_footer.htm
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
jQuery(document).ready(function($){
$("#form1").validate();
});
function postJSON(formId, action, callback) {
function postJSON(formId, action, isReload, callback) {
$.ajax({
url: action,
method: "POST",
dataType: "json",
data: $("#"+formId).serialize(),
success: function(data){
showToastr(data.message, 0);
window.location.reload();
if(isReload)
window.location.reload();

jQuery('#modal-6').modal('hide');
},
error: function(Xhr){
showToastr("出现未知错误,请重试或联系管理员", 0);
Expand Down
Loading

0 comments on commit f68a393

Please sign in to comment.