67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use support\Request;
|
|
use plugin\admin\app\model\Admin;
|
|
use plugin\admin\app\controller\Base;
|
|
use plugin\admin\app\common\Util;
|
|
|
|
class IndexController extends Base
|
|
{
|
|
public function login(Request $request)
|
|
{
|
|
$username = $request->post('username', '');
|
|
$password = $request->post('password', '');
|
|
if (!$username) {
|
|
return $this->json(1, '用户名不能为空');
|
|
}
|
|
$admin = Admin::where('username', $username)->first();
|
|
if (!$admin || !Util::passwordVerify($password, $admin->password)) {
|
|
return $this->json(1, '账户不存在或密码错误');
|
|
}
|
|
if ($admin->status != 0) {
|
|
return $this->json(1, '当前账户暂时无法登录');
|
|
}
|
|
$admin->login_at = date('Y-m-d H:i:s');
|
|
$admin->save();
|
|
$admin = $admin->toArray();
|
|
$session = $request->session();
|
|
unset($admin['password']);
|
|
$session->set('admin', $admin);
|
|
return $this->json(200, '登录成功', [
|
|
"userinfo" => [
|
|
"id" => 1,
|
|
"username" => $admin['username'],
|
|
"nickname" => $admin['nickname'],
|
|
"avatar" => $admin['avatar'],
|
|
"password" => ''
|
|
],
|
|
'token' => [
|
|
"tokenName" => 'satoken',
|
|
"tokenValue" => $request->sessionId(),
|
|
"isLogin" => "true",
|
|
"loginId" => "1",
|
|
"loginType" => "login",
|
|
"tokenTimeout" => 2592000,
|
|
"sessionTimeout" => 2592000,
|
|
"tokenSessionTimeout" => 2591893,
|
|
"tokenActivityTimeout" => -1,
|
|
"loginDevice" => "default-device",
|
|
"tag" => null
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function getOssInfo(Request $request){
|
|
return $this->json(200,'ok',['bucketURL'=>getenv('HTTP')]);
|
|
}
|
|
|
|
public function logout(Request $request)
|
|
{
|
|
$session = $request->session();
|
|
$session->delete('admin');
|
|
return $this->json(200, '退出成功');
|
|
}
|
|
}
|