123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace App\Http\Controllers\Teacher\Auth;
- use App\Models\Teacher;
- use App\Http\Controllers\Teacher\Controller;
- use Illuminate\Foundation\Auth\AuthenticatesUsers;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Validator;
- class LoginController 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;
- /**
- * Where to redirect users after login.
- *
- * @var string
- */
- protected $redirectTo = '/teacher';
- /**
- * 重写登录视图页面
- * @author 晚黎
- * @date 2016-09-05T23:06:16+0800
- * @return [type] [description]
- */
- public function showLoginForm()
- {
- return view('teacher.auth.login');
- }
- /**
- * 自定义认证驱动
- * @author 晚黎
- * @date 2016-09-05T23:53:07+0800
- * @return [type] [description]
- */
- protected function guard()
- {
- return auth()->guard('teacher');
- }
- public function username()
- {
- return 'phone';
- }
- public function login(Request $request)
- {
- $validator = Validator::make($request->all(), [
- $this->username() => 'required|string',
- 'password' => 'required|string'
- ]);
- if($validator->fails()) {
- return back()->withErrors($validator);
- }
- // If the class is using the ThrottlesLogins trait, we can automatically throttle
- // the login attempts for this application. We'll key this by the username and
- // the IP address of the client making these requests into this application.
- if ($this->hasTooManyLoginAttempts($request)) {
- $this->fireLockoutEvent($request);
- return $this->sendLockoutResponse($request);
- }
- if ($this->attemptLogin($request)) {
- return $this->sendLoginResponse($request);
- }
- // If the login attempt was unsuccessful we will increment the number of attempts
- // to login and redirect the user back to the login form. Of course, when this
- // user surpasses their maximum number of attempts they will get locked out.
- $this->incrementLoginAttempts($request);
- return $this->showWarning('密码或者手机错误', '/teacher/login');
- // return $this->sendFailedLoginResponse($request);
- }
- public function logout()
- {
- Auth::guard('teacher')->logout();
- return redirect('/teacher/login');
- }
- public function showChangePasswordForm(Request $request)
- {
- return view('teacher.auth.change-password');
- }
- public function changePassword(Request $request)
- {
- $teacher = Auth::guard('teacher')->user();
- if(!empty($request->input('password'))) {
- $teacher->password = bcrypt($request->input('password'));
- $teacher->save();
- }
- return $this->showMessage('操作成功');
- }
- }
|