public function login() { if ($this->AjaxRequest) { if (!($name = $this->post("name"))) { return $this->renderJson(['code' => 400, 'errmsg' => 'Missing required parameter:$username.']); } if (!($passwd = $this->post("passwd"))) { return $this->renderjson(['code' => 400, 'errmsg' => "Missing required parameter: {$password}"]); } $userModel = Model::make("User"); if (!($userObj = $userModel->getUserByName($name))) { return $this->renderJson(['code' => 401, "errmsg" => "Incorrect password input"]); } //var_dump( $passwd, $userObj->passwd ); if (!tPassword::verify($passwd, $userObj->passwd)) { return $this->renderJson(['code' => 401, 'errmsg' => "incorrect password input"]); } tSession::login($userObj, $this->server("HTTP_USER_AGENT")); $this->updateLoginInfo($userObj, $this->server("REMOTE_ADDR")); if ($http_referer = $this->post("http_referer")) { $go_url = $http_referer; } else { $go_url = "/admin/dashBoard.html"; } return $this->renderJson(['code' => 200, 'errmsg' => 'ok', 'go_url' => $go_url]); } else { return $this->renderJson(["code" => 403, "errmsg" => "Access forbindden"]); } }
public function submit() { if ($this->AjaxRequest) { $user = tSession::getLoginedUserInfo(); $userModel = Model::make("User"); $userObj = $userModel->getUserById($user->id); if ($sname = strip_tags($this->post("sname"))) { $userObj->sname = $user->sname = $sname; } if ($email = strip_tags($this->post("email"))) { $userObj->email = $user->email = $email; } if ($avatar = strip_tags($this->post('avatar'))) { $userObj->avatar = $user->avatar = $avatar; $SiteInfoModel = Model::make("SiteInfo"); $site = $SiteInfoModel->getMeta("site_favicon"); //在模型处做了适配,所以这里不用判断$site的类型 $site->val = $avatar; $site->save(); /*if( !$site ){ $favicon = []; $favicon['meta'] = "site_favicon"; $favicon['val'] = $avatar; $SiteInfoModel->insert( $favicon ); } else{ $site->val = $avatar; $site->save(); }*/ } if ($oldpasswd = $this->post('oldpassword')) { if (!tPassword::verify($oldpasswd, $userObj->passwd)) { return $this->renderJson(403, "原密码不正确!"); } } if ($newPwd = $this->post('newpassword')) { $userObj->passwd = tPassword::hash($newPwd); } $userObj->save(); tSession::login($user, $this->server("HTTP_USER_AGENT")); return $this->renderJson(200, "修改成功"); } }