You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
<?php
|
|
|
|
namespace app\admin\controller;
|
|
|
|
class Auth extends \app\AdminRest
|
|
{
|
|
public function __construct(\think\App $app)
|
|
{
|
|
parent::__construct($app);
|
|
}
|
|
public function auth()
|
|
{
|
|
$filter = $this->_input["user"];
|
|
$admin_model = new \app\admin\model\Admin();
|
|
$admin = $admin_model->getAdmin(["account" => $filter["account"], "uniacid" => $this->_uniacid]);
|
|
if (empty($admin)) {
|
|
return $this->error("account is not exist ,please check user account.");
|
|
}
|
|
if (!checkPasswd($filter["passwd"], $admin["offset"], $admin["passwd"])) {
|
|
return $this->error("passwd is error ,please check user passwd.");
|
|
}
|
|
unset($admin["passwd"]);
|
|
unset($admin["offset"]);
|
|
$result["user"] = $admin;
|
|
$result["token"] = createToken();
|
|
if (empty($result["token"])) {
|
|
return $this->error("System is busy,please try again later.");
|
|
}
|
|
setUserForToken($result["token"], $admin);
|
|
return $this->success($result);
|
|
}
|
|
public function unAuth()
|
|
{
|
|
if (empty($this->_user)) {
|
|
return $this->error("The user is not logged in.");
|
|
}
|
|
delUserForToken($this->_token);
|
|
return $this->success(true);
|
|
}
|
|
} |