12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Http\Controllers\Auth;
- use DB;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Foundation\Auth\AuthenticatesUsers;
- class LoginBaseController extends Controller
- {
- /*
- |--------------------------------------------------------------------------
- | Login Controller
- |--------------------------------------------------------------------------
- |
- | This controller handles authenticating users for the application and
- | redirecting them to your home screen. The controller uses a trait
- | to conveniently provide its functionality to your applications.
- |
- */
- use AuthenticatesUsers;
- /**
- * 重写 Validate the user login request.
- *
- * @param \Illuminate\Http\Request $request
- * @return void
- */
- public function validateLogin(Request $request)
- {
- $this->validate($request, [
- $this->username() => 'required|string|max:25',
- 'password' => 'required|string|min:6|max:16',
- 'captcha' => 'required|captcha',
- ]);
- }
- /**
- * 重写 The user has been authenticated.
- *
- * @param \Illuminate\Http\Request $request
- * @param mixed $user
- * @return mixed
- */
- protected function authenticated(Request $request, $user)
- {
- $time = Carbon::now();
- DB::table($this->usertable())
- ->where('name', $user->name)
- ->update([
- 'last_time' => $time,
- ]);
- }
- /**
- * 重写 Get the login username to be used by the controller.
- *
- * @return string
- */
- public function username()
- {
- return 'name';
- }
- /**
- * 重写 Log the user out of the application.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function logout(Request $request)
- {
- $this->guard()->logout();
- return redirect($this->redirectToLogout());
- }
- /**
- * 重写 Get the post register / login redirect path.
- *
- * @return string
- */
- public function redirectPath()
- {
- if (method_exists($this, 'redirectTo')) {
- return $this->redirectTo();
- }
- return property_exists($this, 'redirectTo') ? $this->redirectTo : '/';
- }
- }
|