Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. <script>
  2. $(document).ready(function(){
  3. $("#submit").click(function(e){
  4. e.preventDefault();
  5. email = $("#email").val();
  6. password = $("#password").val();
  7. $.ajax({
  8. type:"POST",
  9. data:{"email":email, "password":password, "_token":"{{csrf_token()}}"},
  10. url:"{{URL::to('login_redirect')}}",
  11. success:function(data){
  12. if (typeof data !== 'object') {
  13. data = JSON.parse(data);
  14. }
  15. if (data.redirect)
  16. {
  17. window.location.replace(data.redirect);
  18. }
  19. else
  20. {
  21. $("#success").html('<p style="color:red;">' + data.error + '</p>');
  22. }
  23. }
  24. });
  25. });
  26. });
  27. </script>
  28. <div id="success"></div>
  29. <input type="text" name="email" id="email" placeholder="Email">
  30. <input type="password" name="password" id="password" placeholder="Password">
  31. <input type="submit" name="submit" id="submit" class="btn btn-primary">
  32.  
  33. <?php
  34. namespace AppHttpControllers;
  35. use IlluminateHttpRequest;
  36. use AppHttpControllersController;
  37. use AppHttpRequests;
  38. use Auth;
  39. use Session;
  40. use DB;
  41.  
  42. class Mycontroller extends Controller
  43. {
  44. public function login_redirect(Request $request)
  45. {
  46. $email = $request->input('email');
  47. $password = $request->input('password');
  48. $sql = DB::table('user')->where('email', '=', $email)->where('password', '=', $password)->count();
  49. if($sql > 0)
  50. {
  51. $query = DB::table('user')->where('email', '=', $email)->where('password', '=', $password)->get();
  52. Session::put('user', $query);
  53. if (!isset($_POST))
  54. {
  55. header ("Location: dashboard");
  56. }
  57. else
  58. {
  59. echo json_encode(array('redirect' => "dashboard"));
  60. }
  61. }
  62. else
  63. {
  64. echo json_encode(array('error' => 'Wrong email or password or may be your account not activated.'));
  65. }
  66. }
  67.  
  68. public function dashboard()
  69. {
  70. $user = Session::get('user');
  71. return view('user.dashboard',['data'=>$user]);
  72. }
  73.  
  74. public function logout(Request $request) {
  75. Auth::logout();
  76. Session::flush();
  77. return redirect('/login');
  78. }
  79. }
  80.  
  81. <?php
  82. if(empty($data))
  83. {
  84. header('location:{{url("login")}}');
  85. }
  86. ?>
  87. @if (is_array($data) || is_object($data))
  88. @foreach($data as $row)
  89. <h3>Welcome, {{ $row->username }}</h3>
  90. @endforeach
  91. @endif
  92. <a href="{{url('logout')}}">Logout</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement