|
@@ -2,14 +2,95 @@
|
|
|
|
|
|
namespace App\Admin\Controllers;
|
|
namespace App\Admin\Controllers;
|
|
|
|
|
|
|
|
+use App\Models\DistAdminDistributor;
|
|
|
|
+use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Http\Controllers\AuthController as BaseAuthController;
|
|
use Dcat\Admin\Http\Controllers\AuthController as BaseAuthController;
|
|
use Dcat\Admin\Http\Repositories\Administrator;
|
|
use Dcat\Admin\Http\Repositories\Administrator;
|
|
|
|
+use Dcat\Admin\Layout\Content;
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
+use Illuminate\Support\Facades\Session;
|
|
|
|
+use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class AuthController extends BaseAuthController
|
|
class AuthController extends BaseAuthController
|
|
{
|
|
{
|
|
protected $view = 'admin.pages.login';
|
|
protected $view = 'admin.pages.login';
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Login interface.重写登录接口
|
|
|
|
+ * @param Request $request
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public function postLogin(Request $request)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ $credentials = $request->only([$this->username(), 'password', 'captcha']);
|
|
|
|
+ $remember = (bool)$request->input('remember', false);
|
|
|
|
+
|
|
|
|
+ /** @var \Illuminate\Validation\Validator $validator */
|
|
|
|
+ $validator = Validator::make($credentials, [
|
|
|
|
+ $this->username() => 'required',
|
|
|
|
+ 'password' => 'required',
|
|
|
|
+ 'captcha' => 'required',
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if ($request->input('captcha') != Session::get('captcha'))
|
|
|
|
+ {
|
|
|
|
+ $session_captcha = Session::get('captcha');
|
|
|
|
+
|
|
|
|
+ //Session::forget('captcha');
|
|
|
|
+ return response()->json([
|
|
|
|
+ 'success' => false,
|
|
|
|
+ 'message' => 'The captcha['.$session_captcha.'] is incorrect. Please refresh the page and try again.',
|
|
|
|
+ 'refresh_captcha' => true, // 通知前端刷新验证码
|
|
|
|
+ ], 422);; // 422 表示 Unprocessable Entity
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ //Session::forget('captcha');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ unset($credentials['captcha']);
|
|
|
|
+
|
|
|
|
+ if ($validator->fails()) {
|
|
|
|
+ return $this->validationErrorsResponse($validator);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($this->guard()->attempt($credentials, $remember)) {
|
|
|
|
+
|
|
|
|
+ // 登录成功后返回登录响应
|
|
|
|
+ return $this->sendLoginResponse($request);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $this->validationErrorsResponse([
|
|
|
|
+ $this->username() => $this->getFailedLoginMessage(),
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 重写登录控制器
|
|
|
|
+ * @param Content $content
|
|
|
|
+ * @return Content
|
|
|
|
+ */
|
|
|
|
+ function getLogin(Content $content)
|
|
|
|
+ {
|
|
|
|
+ $lang = request()->query('lang');
|
|
|
|
+
|
|
|
|
+ if(!empty($lang))
|
|
|
|
+ {
|
|
|
|
+ switchLanguage($lang);
|
|
|
|
+ return response()->json(['success' => true, 'lang' => $lang]);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($this->guard()->check()) {
|
|
|
|
+ return redirect($this->getRedirectPath());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $content->full()->body(view($this->view));
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Model-form for user setting.
|
|
* Model-form for user setting.
|
|
*
|
|
*
|
|
@@ -77,4 +158,5 @@ class AuthController extends BaseAuthController
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|