LoginController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }
  51. else{
  52. $credentials = [
  53. 'email' => $request->email,
  54. 'password' => $request->password,
  55. 'status' => '1'
  56. ];
  57. if (Auth::attempt($credentials)) {
  58. return redirect('home');
  59. }
  60. else{
  61. return redirect('/login')->with('error','Wrong Email/Password combination');
  62. }
  63. }
  64. }
  65. }
  66. }