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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
| <?php namespace app\home\controller;
use think\exception\ValidateException; use think\facade\Db; use think\facade\View; use app\common\model\User; use think\facade\Request; use app\common\controller\Auth;
class Member extends Base {
public function index() { if (session("?UID")) { $data = ["uid" => session("UID")]; $record = session("Record"); $recordArr = explode(",", $record); $username = Db::name("user")->where($data)->value("username"); return View::fetch('member/index',["username" => $username,"record_list" => $recordArr]); } return view('member/index',["username" => "Are you Login?","record_list" => ""]); } public function login() { if (Request::isPost()){ $username = input("username"); $password = md5(input("password")); $data["username"] = $username; $data["password"] = $password; $userId = Db::name("user")->where($data)->value("uid"); $userStatus = Db::name("user")->where($data)->value("status"); if ($userStatus == 1){ return "<script>alert(\"该用户已被禁用,无法登陆\");history.go(-1)</script>"; } if ($userId){ session("UID",$userId); return redirect("/home/member/index"); } return "<script>alert(\"用户名或密码错误\");history.go(-1)</script>"; }else{ return view('login'); } } public function register() { if (Request::isPost()){ $data = input("post."); if (!(new Auth)->validRegister($data)){ return "<script>alert(\"当前用户名已注册\");history.go(-1)</script>"; } $data["password"] = md5($data["password"]); $data["status"] = 0; $res = User::create($data); if ($res){ return redirect('/home/member/login'); } return "<script>alert(\"注册失败\");history.go(-1)</script>"; }else{ return View("register"); } } public function logout() { session("UID",NULL); return "<script>location.href='/home/member/login'</script>"; } public function updateUser() { $data = input("post."); $update = Db::name("user")->where("uid",session("UID"))->update($data); if($update){ return json(["code" => 1, "msg" => "修改成功"]); } return json(["code" => 0, "msg" => "修改失败"]); } public function rePassword() { $oldPassword = input("oldPassword"); $password = input("password"); $where["uid"] = session("UID"); $where["password"] = md5($oldPassword); $res = Db::name("user")->where($where)->find(); if ($res){ $rePassword = User::update(["password" => md5($password)],["uid"=> session("UID")]); if ($rePassword){ return json(["code" => 1, "msg" => "修改成功"]); } return json(["code" => 0, "msg" => "修改失败"]); } return json(["code" => 0, "msg" => "原密码错误"]); } public function search() { if (Request::isPost()){ if (!session('?UID')) { return redirect('/home/member/login'); } $data = input("post."); $record = session("Record"); if (!session("Record")) { session("Record",$data["key"]); } else { $recordArr = explode(",",$record); $recordLen = sizeof($recordArr); if ($recordLen >= 3){ array_shift($recordArr); session("Record",implode(",",$recordArr) . "," . $data["key"]); return View::fetch("result",["res" => "There's nothing here"]); } } session("Record",$record . "," . $data["key"]); return View::fetch("result",["res" => "There's nothing here"]); }else{ return View("search"); } }
}
|