|
|
@@ -469,6 +469,50 @@ class AdministratorController extends Controller
|
|
|
return view('admin.login');
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 后台登录图形验证码(GD)
|
|
|
+ */
|
|
|
+ public function loginCaptcha(Request $request)
|
|
|
+ {
|
|
|
+ if (!function_exists('imagecreatetruecolor')) {
|
|
|
+ abort(503, 'GD extension required');
|
|
|
+ }
|
|
|
+
|
|
|
+ $chars = '23456789ABCDEFGHJKLMNPQRSTUVWXY';
|
|
|
+ $code = '';
|
|
|
+ $len = strlen($chars) - 1;
|
|
|
+ for ($i = 0; $i < 4; $i++) {
|
|
|
+ $code .= $chars[random_int(0, $len)];
|
|
|
+ }
|
|
|
+ $request->session()->put('admin_login_captcha', strtolower($code));
|
|
|
+
|
|
|
+ $w = 120;
|
|
|
+ $h = 42;
|
|
|
+ $im = imagecreatetruecolor($w, $h);
|
|
|
+ $bg = imagecolorallocate($im, 248, 249, 250);
|
|
|
+ imagefilledrectangle($im, 0, 0, $w, $h, $bg);
|
|
|
+ for ($i = 0; $i < 5; $i++) {
|
|
|
+ $lineColor = imagecolorallocate($im, random_int(180, 230), random_int(180, 230), random_int(180, 230));
|
|
|
+ imageline($im, random_int(0, $w), random_int(0, $h), random_int(0, $w), random_int(0, $h), $lineColor);
|
|
|
+ }
|
|
|
+ for ($i = 0; $i < 50; $i++) {
|
|
|
+ $px = imagecolorallocate($im, random_int(150, 200), random_int(150, 200), random_int(150, 200));
|
|
|
+ imagesetpixel($im, random_int(0, $w - 1), random_int(0, $h - 1), $px);
|
|
|
+ }
|
|
|
+ $textColor = imagecolorallocate($im, random_int(40, 90), random_int(40, 90), random_int(40, 90));
|
|
|
+ imagestring($im, 5, 32, 13, $code, $textColor);
|
|
|
+
|
|
|
+ ob_start();
|
|
|
+ imagepng($im);
|
|
|
+ imagedestroy($im);
|
|
|
+ $png = ob_get_clean();
|
|
|
+
|
|
|
+ return response($png, 200)
|
|
|
+ ->header('Content-Type', 'image/png')
|
|
|
+ ->header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0')
|
|
|
+ ->header('Pragma', 'no-cache');
|
|
|
+ }
|
|
|
+
|
|
|
public function checkLogin(Request $request)
|
|
|
{
|
|
|
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5); //只取前4位,这样只判断最优先的语言。如果取前5位,可能出现en,zh的情况,影响判断。
|
|
|
@@ -486,6 +530,12 @@ class AdministratorController extends Controller
|
|
|
return $this->json(500, trans('cs.login.notice_pass'));
|
|
|
}
|
|
|
|
|
|
+ $captchaInput = isset($post['captcha']) ? strtolower(trim((string) $post['captcha'])) : '';
|
|
|
+ $captchaSession = (string) $request->session()->pull('admin_login_captcha', '');
|
|
|
+ if ($captchaInput === '' || $captchaSession === '' || !hash_equals($captchaSession, $captchaInput)) {
|
|
|
+ return $this->json(500, trans('cs.login.wrong_captcha'));
|
|
|
+ }
|
|
|
+
|
|
|
$admin = AdminUser::where('account', $post['account'])->first();
|
|
|
|
|
|
if (empty($admin) || $admin->type != 1) {
|