LoginController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Http\Controllers\TeacherAuth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Foundation\Auth\AuthenticatesUsers;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Http\Request;
  7. use App\User;
  8. class LoginController extends Controller
  9. {
  10. /*
  11. |--------------------------------------------------------------------------
  12. | Login Controller
  13. |--------------------------------------------------------------------------
  14. |
  15. | This controller handles authenticating users for the application and
  16. | redirecting them to your home screen. The controller uses a trait
  17. | to conveniently provide its functionality to your applications.
  18. |
  19. */
  20. /**
  21. * Where to redirect users after login / registration.
  22. *
  23. * @var string
  24. */
  25. public $redirectTo = '/teacher_profile';
  26. /**
  27. * Create a new controller instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct()
  32. {
  33. $this->middleware('teacher.guest', ['except' => 'logout']);
  34. }
  35. /**
  36. * Show the application's login form.
  37. *
  38. * @return \Illuminate\Http\Response
  39. */
  40. public function showLoginForm()
  41. {
  42. return view('login-v2');
  43. }
  44. public function login(Request $request)
  45. {
  46. $teacher = User::where(
  47. 'user_type',2
  48. )->where(
  49. 'email',$request->email
  50. )->first();
  51. if(!$teacher){
  52. return redirect('/login-v2')->with('error','Unknown Email address!');
  53. }else{
  54. if($teacher->apply_status == 0){
  55. return redirect('/login-v2')->with('error', 'Your account is still under review.');
  56. }
  57. else{
  58. $credentials = [
  59. 'email' => $request->email,
  60. 'password' => $request->password,
  61. 'apply_status' => '1',
  62. 'status' => '1',
  63. ];
  64. if (Auth::guard('teacher')->attempt($credentials)) {
  65. $teacher->last_logged_timezone=$request->last_logged_timezone;
  66. $teacher->last_logged_at=now();
  67. $teacher->update();
  68. return redirect('teacher_profile');
  69. }
  70. else{
  71. return redirect('/login-v2')->with('error','Wrong Email/Password combination');
  72. }
  73. }
  74. }
  75. }
  76. public function logout(){
  77. $this->guard('teacher')->logout();
  78. request()->session()->invalidate();
  79. return redirect('/login-v2');
  80. }
  81. /**
  82. * Get the guard to be used during authentication.
  83. *
  84. * @return \Illuminate\Contracts\Auth\StatefulGuard
  85. */
  86. protected function guard()
  87. {
  88. return Auth::guard('teacher');
  89. }
  90. }