Guest User

Untitled

a guest
Aug 30th, 2018
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. Route::get('/home', 'HomeController@index')->name('home');
  2. Route::post('login', 'authController@logIn');
  3. Route::get('logout', 'authController@weblogOut');
  4.  
  5. Route::get('login', 'authController@showLogInPage');
  6. Route::post('check_login', 'authController@checkLoginForWeb');
  7. Route::get('web_logout', 'authController@webLogOut');
  8.  
  9. <form method="POST" action="{{ url('check_login') }}" aria-label="{{ __('Login') }}">
  10. @csrf
  11. <div class="form-group has-feedback">
  12. <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}"
  13. name="email" placeholder="Email" value="{{ old('email') }}" required autofocus>
  14. <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
  15. </div>
  16. <div class="form-group has-feedback">
  17. <input id="password" type="password"
  18. class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password"
  19. placeholder="Password" required>
  20. <span class="glyphicon glyphicon-lock form-control-feedback"></span>
  21. </div>
  22. <div class="row">
  23. <div class="col-xs-8">
  24. <div class="checkbox icheck">
  25. <label class="form-check-label" for="remember">
  26. <input type="checkbox"> Remember Me
  27. </label>
  28. </div>
  29. </div>
  30. <!-- /.col -->
  31. <div class="col-xs-4">
  32. <button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
  33. </div>
  34. <!-- /.col -->
  35. </div>
  36. </form>
  37.  
  38. public function logIn(Request $request) {
  39. try {
  40. $validation = Validator::make($request->All(), [
  41. 'email' => 'required|email',
  42. 'password' => 'required|max:50'
  43. ]);
  44. if ($validation->fails()) {
  45. $error = $validation->getMessageBag()->getMessages();
  46. return Response::json(['Error' => $error], 400);
  47. }
  48. $email = $request->all()['email'];
  49. $password = $request->all()['password'];
  50.  
  51. $user = User::where('email', $email)->firstOrFail();
  52. if (Hash::check($password, $user->password)) {
  53. session()->flush();
  54. session()->push('user', $user);
  55. return redirect('home');
  56. //return Response::json(["Success" => "Log In Successful"], 200);
  57. }
  58. throw new Exception();
  59.  
  60. } catch (Exception $exception) {
  61. return Response::json(["Error" => "Login Failed"], 400);
  62. }
  63. }
Add Comment
Please, Sign In to add comment