LoginController.php 2.6 KB

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