Files
Pro/application/console/controller/Login.php
T
2026-02-25 01:50:31 +08:00

80 lines
3.0 KiB
PHP

<?php
namespace app\console\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;
use verifycode\Verify;
class Login extends Controller{
public function index(){
if(Session::get('user_info')){
$this->redirect('/',301);
}
return $this->fetch();
}
/**
* 处理登录
*/
public function dologin(){
if(Request::instance()->post()){
$username = Request::instance()->post('account');
$password = Request::instance()->post('password');
// $verifycode = strtolower(Request::instance()->post('code'));
// if(md5($verifycode) != Session::get("img_verify")){
// Session::delete('user_info');
// $this->error('验证码错误','login/index');
// }
$find = Db::name('user_controller')->where(array('username' => $username, 'is_delete' => 0))->find();
if(!$find){
Session::delete('user_info');
return json(['code' => 0, 'msg' => '用户不存在']);
}
if(think_ucenter_md5($password, UC_AUTH_KEY) === $find['password'] && $find['password']){
Session::set('user_info',$find);
Db::name('user_controller')->where(array('id' => $find['id']))->update(array('last_login_time' => time(), 'last_login_ip' => getIP()));
$tableInfo = Db::name('table')->where(array('id' => $find['table_id']))->find();
if($tableInfo['game_id'] == 2){
return json(['code'=>1,'msg'=>'登录成功','url'=>'/index/tab_dt']);
}else if($tableInfo['game_id'] == 3){
return json(['code'=>1,'msg'=>'登录成功','url'=>'/dn/index']);
}else if($tableInfo['game_id'] == 4){
return json(['code'=>1,'msg'=>'登录成功','url'=>'/nn/index']);
}else if($tableInfo['game_id'] == 5){
return json(['code'=>1,'msg'=>'登录成功','url'=>'/tc/index']);
}else if($tableInfo['game_id'] == 1 && $tableInfo['mode'] == 2){
return json(['code'=>1,'msg'=>'登录成功','url'=>'/index/tab_b_win6']);
}else if($tableInfo['game_id'] == 1 && $tableInfo['mode'] != 2){
return json(['code'=>1,'msg'=>'登录成功','url'=>'/index/tab_b']);
}else{
Session::delete('user_info');
return json(['code'=>0,'msg'=>'账户信息出错']);
}
/*
$preview_url = Session::get('preview_url');
if($preview_url){
return json(['code'=>1,'msg'=>'登录成功','url'=>$preview_url]);
}else{
return json(['code'=>1,'msg'=>'登录成功','url'=>'/']);
}
*/
}else{
Session::delete('user_info');
return json(['code'=>0,'msg'=>'密码错误']);
}
}
}
/**
* 退出登录
*/
public function logout(){
Session::clear();
$this->redirect('login/index',301);
}
/**
* 验证码
*/
public function verifycode(){
$verify = new verify();
$verify->doimg();
}
}