This commit is contained in:
li
2026-01-28 23:48:20 +08:00
commit b8cd0c9418
1293 changed files with 184011 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use app\middleware\checkLogin;
class Common{
protected $middleware = [checkLogin::class];
public function initialize(){
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Session;
use think\facade\Request;
use think\facade\Lang;
use think\response\Json;
use think\facade\Env;
class Index extends Common{
//首页
public function index(){
$tables = Db::name('table')->where(['status' => 1])->select()->toArray();
$user_info = Session::get('user_info');
$user = Db::name('user')->where(['id' => $user_info['id']])->find();
$login_token = create_login_token($user);
$api_token = $login_token;
Db::name('user')->where(['id' => $user_info['id']])->update(['login_token' => $login_token, 'api_token' => $api_token]);
View::assign('api_token',$api_token);
View::assign('login_token',$login_token);
View::assign('tables',$tables);
View::assign('user',$user);
View::assign('websocketUrl',Env::get('system.WEBSOCKET'));
View::assign('websocketProtocol',Env::get('system.PROTOCOL'));
return View::fetch();
}
function get_lang(): Json
{
if(!Request::instance()->isPost()) return json();
$lang = Lang::get();
return json(array('status' => 1, 'lang' => $lang));
}
}
+50
View File
@@ -0,0 +1,50 @@
<?php
declare (strict_types = 1);
namespace app\index\controller;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;
use think\response\Redirect;
use think\response\Json;
class Login
{
public function index(){
if(Session::get('user_info')){
return redirect('/login/logout');
}
return View::fetch();
}
/**
* 处理登录
*/
public function dologin(): Json
{
if (!Request::instance()->isPost()) return json();
$username = Request::instance()->post('username');
$password = Request::instance()->post('password');
$find = Db::name('user')->where(array('username' => $username, 'is_delete' => 0, 'status' => 1))->find();
if(!$find){
Session::delete('user_info');
return json(['code' => 0, 'msg' => '用户不存在']);
}
if(think_ucenter_md5($password, UC_AUTH_KEY) == $find['password'] && !empty($find['password'])){
Session::set('user_info',$find);
return json(['code'=>1,'msg'=>'登录成功','url'=>'/']);
}else{
Session::delete('user_info');
return json(['code'=>0,'msg'=>'密码错误']);
}
}
/**
* 退出登录
*/
public function logout(): Redirect
{
Session::delete('user_info');
return redirect('/login/index');
}
}