ComposerUpdate & 修改登录验证码

This commit is contained in:
Anyon 2020-04-02 11:18:10 +08:00
parent 27e8bc8b52
commit a0175b4430
9 changed files with 46 additions and 58 deletions

View File

@ -42,10 +42,12 @@ class Login extends Controller
$this->redirect(url('@admin')->build());
} else {
$this->title = '系统登录';
$this->captcha_type = 'login_captcha';
$this->captcha_token = CodeExtend::uniqidDate(18);
$this->app->session->set($this->captcha_type, $this->captcha_token);
$this->captchaType = 'loginCaptcha';
$this->captchaToken = CodeExtend::uniqidDate(18);
$this->devmode = SystemService::instance()->checkRunMode('dev');
if (!$this->app->session->get('login_input_session_error')) {
$this->app->session->set($this->captchaType, $this->captchaToken);
}
$this->fetch();
}
} else {
@ -64,21 +66,24 @@ class Login extends Controller
$map = ['username' => $data['username'], 'is_deleted' => '0'];
$user = $this->app->db->name('SystemUser')->where($map)->order('id desc')->find();
if (empty($user)) {
$this->app->session->set("login_input_session_error", true);
$this->error('登录账号或密码错误,请重新输入!');
}
if (md5("{$user['password']}{$data['uniqid']}") !== $data['password']) {
$this->app->session->set("login_input_session_error", true);
$this->error('登录账号或密码错误,请重新输入!');
}
if (empty($user['status'])) {
$this->error('账号已经被禁用,请联系管理员!');
}
$this->app->session->delete("login_input_session_error");
$this->app->db->name('SystemUser')->where(['id' => $user['id']])->update([
'login_ip' => $this->app->request->ip(),
'login_at' => $this->app->db->raw('now()'),
'login_num' => $this->app->db->raw('login_num+1'),
]);
sysoplog('用户登录', '登录系统后台成功');
$this->app->session->set('user', $user);
sysoplog('用户登录', "登录系统后台成功");
$this->success('登录成功', url('@admin')->build());
}
}

View File

@ -30,7 +30,7 @@
<i class="layui-icon layui-icon-picture-fine"></i>
<input class="layui-input" required pattern="^\S{4,}$" name="verify" maxlength="4" autocomplete="off" placeholder="验证码" title="请输入验证码">
</label>
<label data-captcha="{:url('admin/login/captcha',[],false)}" data-field-verify="verify" data-field-uniqid="uniqid" data-captcha-type="{$captcha_type}" data-captcha-token="{$captcha_token}"></label>
<label data-captcha="{:url('admin/login/captcha',[],false)}" data-field-verify="verify" data-field-uniqid="uniqid" data-captcha-type="{$captchaType}" data-captcha-token="{$captchaToken}"></label>
</li>
<li class="text-center padding-top-20">
<button type="submit" class="layui-btn layui-disabled full-width" data-form-loaded="立即登入">正在载入</button>

10
composer.lock generated
View File

@ -498,7 +498,7 @@
},
{
"name": "symfony/options-resolver",
"version": "v3.4.38",
"version": "v3.4.39",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
@ -909,12 +909,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "233e269155871ca9ef6b818536687d5862acef5b"
"reference": "e031f91b1c3d64b190f202e6e913bfa301d2ce14"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/233e269155871ca9ef6b818536687d5862acef5b",
"reference": "233e269155871ca9ef6b818536687d5862acef5b",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/e031f91b1c3d64b190f202e6e913bfa301d2ce14",
"reference": "e031f91b1c3d64b190f202e6e913bfa301d2ce14",
"shasum": "",
"mirrors": [
{
@ -958,7 +958,7 @@
],
"description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top",
"time": "2020-03-26T10:28:21+00:00"
"time": "2020-04-01T08:17:31+00:00"
},
{
"name": "zoujingli/wechat-developer",

View File

@ -33,28 +33,23 @@ $(function () {
/*! 登录图形验证码刷新 */
$body.on('click', '[data-captcha]', function () {
var type, token, verify, uniqid, action, $that = $(this);
action = this.getAttribute('data-captcha') || location.href;
if (action.length < 5) return $.msg.tips('请设置验证码请求地址');
type = this.getAttribute('data-captcha-type') || 'captcha-type';
token = this.getAttribute('data-captcha-token') || 'captcha-token';
uniqid = this.getAttribute('data-field-uniqid') || 'uniqid';
verify = this.getAttribute('data-field-verify') || 'verify';
var $that = $(this), $form = $that.parents('form');
var action = this.getAttribute('data-captcha') || location.href;
if (action.length < 5) return $.msg.tips('请设置验证码请求及验证地址');
var type = this.getAttribute('data-captcha-type') || 'captcha-type';
var token = this.getAttribute('data-captcha-token') || 'captcha-token';
var uniqid = this.getAttribute('data-field-uniqid') || 'captcha-uniqid';
var verify = this.getAttribute('data-field-verify') || 'captcha-verify';
$.form.load(action, {type: type, token: token}, 'post', function (ret) {
if (ret.code) {
$that.html('');
$that.append($('<img alt="img" src="">').attr('src', ret.data.image));
$that.append($('<input type="hidden">').attr('name', uniqid).val(ret.data.uniqid));
if (ret.data.code) {
$that.parents('form').find('[name=' + verify + ']').attr('value', ret.data.code);
} else {
$that.parents('form').find('[name=' + verify + ']').attr('value', '');
}
return false;
$that.html('<img alt="img" src="' + ret.data.image + '"><input type="hidden">').find('input').attr('name', uniqid).val(ret.data.uniqid || '');
$form.find('[name="' + verify + '"]').attr('value', ret.data.code || '').val(ret.data.code || '');
return (ret.data.code || $form.find('.verify.layui-hide').removeClass('layui-hide')), false;
}
}, false);
});
/*! 初始化登录图形 */
$('[data-captcha]').map(function () {
$(this).trigger('click')
});

View File

@ -507,8 +507,8 @@
},
{
"name": "symfony/options-resolver",
"version": "v3.4.38",
"version_normalized": "3.4.38.0",
"version": "v3.4.39",
"version_normalized": "3.4.39.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/options-resolver.git",
@ -935,12 +935,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "233e269155871ca9ef6b818536687d5862acef5b"
"reference": "e031f91b1c3d64b190f202e6e913bfa301d2ce14"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/233e269155871ca9ef6b818536687d5862acef5b",
"reference": "233e269155871ca9ef6b818536687d5862acef5b",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/e031f91b1c3d64b190f202e6e913bfa301d2ce14",
"reference": "e031f91b1c3d64b190f202e6e913bfa301d2ce14",
"shasum": "",
"mirrors": [
{
@ -956,7 +956,7 @@
"ext-json": "*",
"topthink/framework": "^6.0"
},
"time": "2020-03-26T10:28:21+00:00",
"time": "2020-04-01T08:17:31+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2020-03-27 10:03:07
// This file is automatically generated at:2020-04-02 11:17:50
declare (strict_types = 1);
return array (
0 => 'think\\app\\Service',

View File

@ -15,6 +15,7 @@
namespace think\admin\service;
use think\admin\extend\CodeExtend;
use think\admin\extend\HttpExtend;
use think\admin\Service;
@ -35,13 +36,7 @@ class ExpressService extends Service
* 网络请求参数
* @var array
*/
protected $options;
/**
* 会话Cookie文件
* @var string
*/
protected $cookies = '';
protected $config;
/**
* 快递服务初始化
@ -49,17 +44,10 @@ class ExpressService extends Service
*/
protected function initialize()
{
$this->cookies = "{$this->app->getRuntimePath()}_express_cookie.txt";
if (file_exists($this->cookies) && filemtime($this->cookies) + 10 < time()) {
@unlink($this->cookies);
}
$this->options = [
'cookie_file' => $this->cookies, 'headers' => [
'Host' => 'express.baidu.com',
'CLIENT-IP' => $this->app->request->ip(),
'X-FORWARDED-FOR' => $this->app->request->ip(),
],
];
$clentip = $this->app->request->ip();
$cookies = "{$this->app->getRootPath()}runtime/.express.cookie";
$headers = ['Host:express.baidu.com', "CLIENT-IP:{$clentip}", "X-FORWARDED-FOR:{$clentip}"];
$this->config = ['cookie_file' => $cookies, 'headers' => $headers];
$this->token = $this->getExpressToken();
return $this;
}
@ -93,7 +81,7 @@ class ExpressService extends Service
public function getExpressList()
{
$data = [];
if (preg_match('/"currentData":.*?\[(.*?)\],/', $this->getWapBaiduHtml(), $matches)) {
if (preg_match('/"currentData":.*?\[(.*?)],/', $this->getWapBaiduHtml(), $matches)) {
foreach (json_decode("[{$matches['1']}]") as $item) $data[$item->value] = $item->text;
unset($data['_auto']);
return $data;
@ -111,9 +99,9 @@ class ExpressService extends Service
*/
private function doExpress($code, $number)
{
$uniqid = strtr(uniqid(), '.', '');
$url = "https://express.baidu.com/express/api/express?tokenV2={$this->token}&appid=4001&nu={$number}&com={$code}&qid={$uniqid}&new_need_di=1&source_xcx=0&vcode=&token=&sourceId=4155&cb=callback";
return json_decode(str_replace('/**/callback(', '', trim(HttpExtend::get($url, [], $this->options), ')')), true);
$qid = CodeExtend::uniqidNumber(19, '7740');
$url = "https://express.baidu.com/express/api/express?tokenV2={$this->token}&appid=4001&nu={$number}&com={$code}&qid={$qid}&new_need_di=1&source_xcx=0&vcode=&token=&sourceId=4155&cb=callback";
return json_decode(str_replace('/**/callback(', '', trim(HttpExtend::get($url, [], $this->config), ')')), true);
}
/**
@ -138,7 +126,7 @@ class ExpressService extends Service
{
$content = $this->app->cache->get('express_kuaidi_html');
while (empty($content) || stristr($content, '百度安全验证') > -1 || stripos($content, 'tokenV2') === -1) {
$content = HttpExtend::get('https://m.baidu.com/s?word=快递查询&rnd=' . uniqid(), [], $this->options);
$content = HttpExtend::get('https://m.baidu.com/s?word=快递查询&rand=' . microtime(true), [], $this->config);
}
$this->app->cache->set('express_kuaidi_html', $content, 30);
return $content;

View File

@ -181,7 +181,7 @@ class QueueService extends Service
return $this->progress($status, $message, $progress);
}
if (is_numeric($status)) $data['status'] = intval($status);
if (is_numeric($progress)) $progress = sprintf("%.2f", $progress);
if (is_numeric($progress)) $progress = str_pad(sprintf("%.2f", $progress), 6, "0", STR_PAD_LEFT);
if (is_string($message) && is_null($progress)) {
$data['message'] = $message;
$data['history'][] = ['message' => $message, 'progress' => $data['progress'], 'datetime' => date('Y-m-d H:i:s')];

View File

@ -176,7 +176,7 @@ class SystemService extends Service
*/
public function putDebug($data, $new = false, $file = null)
{
if (is_null($file)) $file = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . date('Ymd') . '.txt';
if (is_null($file)) $file = $this->app->getRootPath() . 'runtime' . DIRECTORY_SEPARATOR . date('Ymd') . '.log';
$str = (is_string($data) ? $data : ((is_array($data) || is_object($data)) ? print_r($data, true) : var_export($data, true))) . PHP_EOL;
$new ? file_put_contents($file, $str) : file_put_contents($file, $str, FILE_APPEND);
}