LoginController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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('user_type',2)->where('email',$request->email)->first();
  47. if(!$teacher){
  48. return redirect('/')->with('error','Unknown Email address!');
  49. }else{
  50. if($teacher->status == 0){
  51. return redirect('/')->with('error', 'Account Status is not Activated!');
  52. }
  53. else{
  54. $credentials = [
  55. 'email' => $request->email,
  56. 'password' => $request->password,
  57. 'status' => '1'
  58. ];
  59. if (Auth::guard('teacher')->attempt($credentials)) {
  60. return redirect('teacher_profile');
  61. }
  62. else{
  63. return redirect('/')->with('error','Wrong Email/Password combination');
  64. }
  65. }
  66. }
  67. }
  68. public function logout(){
  69. $this->guard('teacher')->logout();
  70. request()->session()->invalidate();
  71. return redirect('/login-v2');
  72. }
  73. /**
  74. * Get the guard to be used during authentication.
  75. *
  76. * @return \Illuminate\Contracts\Auth\StatefulGuard
  77. */
  78. protected function guard()
  79. {
  80. return Auth::guard('teacher');
  81. }
  82. }