diff --git a/Library/Controller/Admin/Invite.php b/Library/Controller/Admin/Invite.php index 3a7175e7..d1e1a066 100644 --- a/Library/Controller/Admin/Invite.php +++ b/Library/Controller/Admin/Invite.php @@ -20,7 +20,7 @@ public function inviteList() { //throw new \Core\Error("user list", 505); global $user; - $inviteList = InviteModel::GetInviteArray(); + $inviteList = InviteModel::GetInviteArray(0); include Template::load('/admin/invite'); } @@ -28,6 +28,7 @@ public function inviteList() { public function inviteOldList() { global $user; + $inviteList = InviteModel::GetInviteArray(1); include Template::load('/admin/invite'); } @@ -35,28 +36,28 @@ public function inviteOldList() { * 添加一个邀请码 */ 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() { @@ -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(); } } \ No newline at end of file diff --git a/Library/Controller/Admin/User.php b/Library/Controller/Admin/User.php index ba13974c..a5924537 100644 --- a/Library/Controller/Admin/User.php +++ b/Library/Controller/Admin/User.php @@ -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'] = '删除账户成功!'; @@ -60,8 +60,8 @@ 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']; @@ -69,10 +69,37 @@ public function modify() { 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(); } } \ No newline at end of file diff --git a/Library/Model/Invite.php b/Library/Model/Invite.php index c445944f..e8a3766c 100644 --- a/Library/Model/Invite.php +++ b/Library/Model/Invite.php @@ -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'); @@ -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(); diff --git a/Library/Model/User.php b/Library/Model/User.php index 054af2b1..df66be4f 100644 --- a/Library/Model/User.php +++ b/Library/Model/User.php @@ -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); @@ -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; } /** @@ -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 */ diff --git a/Resource/Default/css/custom.css b/Resource/Default/css/custom.css index 36ffa42f..9c2501ee 100644 --- a/Resource/Default/css/custom.css +++ b/Resource/Default/css/custom.css @@ -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} diff --git a/Template/Default/admin/_footer.htm b/Template/Default/admin/_footer.htm index d524d3ec..a836255e 100644 --- a/Template/Default/admin/_footer.htm +++ b/Template/Default/admin/_footer.htm @@ -26,7 +26,7 @@ jQuery(document).ready(function($){ $("#form1").validate(); }); - function postJSON(formId, action, callback) { + function postJSON(formId, action, isReload, callback) { $.ajax({ url: action, method: "POST", @@ -34,7 +34,10 @@ 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); diff --git a/Template/Default/admin/invite.htm b/Template/Default/admin/invite.htm index e125cb73..1039dda1 100644 --- a/Template/Default/admin/invite.htm +++ b/Template/Default/admin/invite.htm @@ -35,8 +35,8 @@