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.

172 lines
5.4 KiB

<?php
namespace app\adminapi\controller\v1;
use app\adminapi\ApiController;
use think\facade\Db;
use think\facade\Session;
use thans\jwt\facade\JWTAuth;
use think\facade\Log;
class Auth extends ApiController
{
public function Login()
{
// if (intval($_CFG['captcha']) & CAPTCHA_ADMIN)
// {
// include_once(ROOT_PATH . 'includes/cls_captcha.php');
// /* 檢查驗證碼是否正確 */
// $validator = new captcha();
// if (!empty($_POST['captcha']) && !$validator->check_word($_POST['captcha']))
// {
// sys_msg($_LANG['captcha_error'], 1);
// }
// }
$username = input('username');
$password = input('password');
$ec_salt = Db::name('admin_user')
->where('user_name',$username)
->value('ec_salt');
if(!$ec_salt)
{
$this->Error('Error');
}
/* 檢查密碼是否正確 */
$row = Db::name('admin_user')
->field('user_id, user_name, password, last_login, action_list, last_login,suppliers_id,ec_salt')
->where('user_name',$username)
->where('password',md5(md5($password).$ec_salt))
->find();
if ($row)
{
// 檢查是否為供貨商的管理員 所屬供貨商是否有效
// if (!empty($row['suppliers_id']))
// {
// $supplier_is_check = suppliers_list_info(' is_check = 1 AND suppliers_id = ' . $row['suppliers_id']);
// if (empty($supplier_is_check))
// {
// sys_msg($_LANG['login_disable'], 1);
// }
// }
// 登錄成功
$_SESSION['admin_id'] = $row['user_id'];
$_SESSION['admin_name'] = $row['user_name'];
$_SESSION['action_list'] = $row['action_list'];
$_SESSION['last_check'] = $row['last_login'];
$_SESSION['suppliers_id'] = $row['suppliers_id'];
if($row['action_list'] == 'all' && empty($row['last_login']))
{
$_SESSION['shop_guide'] = true;
}
// 更新最後登錄時間和IP
// $db->query("UPDATE " .$ecs->table('admin_user').
// " SET last_login='" . gmtime() . "', last_ip='" . real_ip() . "'".
// " WHERE user_id='$_SESSION[admin_id]'");
// if (isset($_POST['remember']))
// {
// $time = gmtime() + 3600 * 24 * 365;
// setcookie('ECSCP[admin_id]', $row['user_id'], $time);
// setcookie('ECSCP[admin_pass]', md5($row['password'] . $_CFG['hash_code']), $time);
// }
// 清除購物車中過期的數據
// clear_cart();
// ecs_header("Location: ./index.php\n");
}
return $this->Success($_SESSION);
}
public function captcha($id=''){
return captcha($id);
}
public function checkC($value){
print_r(Session::all());
if(!captcha_check($value)){
//驗證失敗
echo 'failure';
};
echo 'Success';
}
public function getRoute(){
$routes=[
[
"router" => "root",
"children" => [
"DashBoard",
[
"router" => "system",
"children" => [
[
"router" => "systemConfig",
"name" => "站台設置",
"authority" => [
"permission" => "demo",
"role" => "admin"
]
]
]
],
[
"router" => "admin",
"children" => [
"adminUser",
"adminLog",
"adminRole",
]
],
[
"router" => "goods",
"children" => [
"goodsList",
"goodsCategory",
"goodsType",
]
],
[
"router" => "order",
"children" => [
"orderList",
]
],
[
"router" => "room",
"children" => [
"roomList",
]
],
[
"router" => "user",
"children" => [
"userList"
]
],
[
"router" => "setting",
"children" => [
"settingBase",
"settingConfig"
]
]
]
]
];
return $this->Success($routes);
}
}