Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- $(document).ready(function(){
- $("#submit").click(function(e){
- e.preventDefault();
- email = $("#email").val();
- password = $("#password").val();
- $.ajax({
- type:"POST",
- data:{"email":email, "password":password, "_token":"{{csrf_token()}}"},
- url:"{{URL::to('login_redirect')}}",
- success:function(data){
- if (typeof data !== 'object') {
- data = JSON.parse(data);
- }
- if (data.redirect)
- {
- window.location.replace(data.redirect);
- }
- else
- {
- $("#success").html('<p style="color:red;">' + data.error + '</p>');
- }
- }
- });
- });
- });
- </script>
- <div id="success"></div>
- <input type="text" name="email" id="email" placeholder="Email">
- <input type="password" name="password" id="password" placeholder="Password">
- <input type="submit" name="submit" id="submit" class="btn btn-primary">
- <?php
- namespace AppHttpControllers;
- use IlluminateHttpRequest;
- use AppHttpControllersController;
- use AppHttpRequests;
- use Auth;
- use Session;
- use DB;
- class Mycontroller extends Controller
- {
- public function login_redirect(Request $request)
- {
- $email = $request->input('email');
- $password = $request->input('password');
- $sql = DB::table('user')->where('email', '=', $email)->where('password', '=', $password)->count();
- if($sql > 0)
- {
- $query = DB::table('user')->where('email', '=', $email)->where('password', '=', $password)->get();
- Session::put('user', $query);
- if (!isset($_POST))
- {
- header ("Location: dashboard");
- }
- else
- {
- echo json_encode(array('redirect' => "dashboard"));
- }
- }
- else
- {
- echo json_encode(array('error' => 'Wrong email or password or may be your account not activated.'));
- }
- }
- public function dashboard()
- {
- $user = Session::get('user');
- return view('user.dashboard',['data'=>$user]);
- }
- public function logout(Request $request) {
- Auth::logout();
- Session::flush();
- return redirect('/login');
- }
- }
- <?php
- if(empty($data))
- {
- header('location:{{url("login")}}');
- }
- ?>
- @if (is_array($data) || is_object($data))
- @foreach($data as $row)
- <h3>Welcome, {{ $row->username }}</h3>
- @endforeach
- @endif
- <a href="{{url('logout')}}">Logout</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement