LoginController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use App\Providers\RouteServiceProvider;
  6. use Illuminate\Foundation\Auth\AuthenticatesUsers;
  7. use App\User;
  8. use Auth;
  9. class LoginController extends Controller
  10. {
  11. /*
  12. |--------------------------------------------------------------------------
  13. | Login Controller
  14. |--------------------------------------------------------------------------
  15. |
  16. | This controller handles authenticating users for the application and
  17. | redirecting them to your home screen. The controller uses a trait
  18. | to conveniently provide its functionality to your applications.
  19. |
  20. */
  21. //use AuthenticatesUsers;
  22. /**
  23. * Where to redirect users after login.
  24. *
  25. * @var string
  26. */
  27. //protected $redirectTo = RouteServiceProvider::HOME;
  28. public $redirectTo = '/home';
  29. /**
  30. * Create a new controller instance.
  31. *
  32. * @return void
  33. */
  34. public function __construct()
  35. {
  36. $this->middleware('guest')->except('logout');
  37. }
  38. public function showLoginForm()
  39. {
  40. return view('auth.login');
  41. }
  42. public function login(Request $request)
  43. {
  44. $student = User::where('user_type',1)->where('email',$request->email)->first();
  45. if(!$student){
  46. return redirect('/login')->with('error','Unknown Email address!');
  47. }else{
  48. if($student->status == 0){
  49. return redirect('/login')->with('error', 'Account Status is not Activated!');
  50. }else{
  51. $credentials = [
  52. 'email' => $request->email,
  53. 'password' => $request->password,
  54. 'status' => '1'
  55. ];
  56. if (Auth::attempt($credentials)) {
  57. return redirect('home');
  58. }
  59. else{
  60. return redirect('/login')->with('error','Wrong Email/Password combination');
  61. }
  62. }
  63. }
  64. }
  65. }