Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jakegroves's avatar

auth.login listener creating 'fail' pop-up

I am using the auth.login listener, the listener works but there is something wrong with my handle function, can't work out what the problem is or if there is something i am doing that is not allowed in the auth.login listener??

listener class handle method:

public function handle($event)
    {
        $user = Auth::user();
        if ($user->level == 3) {
            $students = User::where('level', 1)->get();
            foreach ($students as $student) {
              if (\App\library\MyFunctions::percentage($student->attendance->where('attended', 'true')->count(), $student->attendance->count()) >= 90) {
                  exit;
              }
              elseif (\App\library\MyFunctions::percentage($student->attendance->where('attended', 'true')->count(), $student->attendance->count()) >= 1) {
                  Notification::create([
                      'user_id' => '1',
                      'action' => $studnet->name .' has poor attendance, in one of their classes.',
                      'added_by' => 'system',
                      'read' => '0',
                  ]);
              }
            }
        }
        else {      }
    }

the code in that method works if i do all that manually in a view and controller?? (tested)

any insight be great

0 likes
1 reply
jakegroves's avatar

Okay the error seems to be coming from my javascript. If i login using http://localhost:8000/login it works fine.

But i have a login dropdown box on the nav menu which is controlled by jquery in my site.js file

$('#login-nav').submit(function() {
    var email = $("#email").val();
    var password = $("#password").val();
    var formData = {
        email    : email,
        password : password,
        _token : $('input[name=_token]').val()
    }

    var notify = $.notify('<strong>Submitting </strong>login please wait ...', {
        type: 'success',
        allow_dismiss: false,
        showProgressbar: true
    })
    if (email == "" && password == "") {
        setTimeout(function() {
            notify.update('message', '<strong>No</strong> e-mail address and password was entered upon login.');
            notify.update('type', 'danger');
            notify.update('progress', 100);
        }, 1000);
        $("#email").addClass("has-error");
        $("#password").addClass("has-error");
        setTimeout(function() {
            $.notify({ // options
                icon: 'fa fa-danger',
                message: "Please enter an e-mail address and password to login!"
            },{ // settings
                type: 'danger',
                animate: {
                        enter: 'animated fadeInDown',
                        exit: 'animated fadeOutUp'
                }
            });
        }, 2000);
        return false;
    }
    else if (password == "") {
        setTimeout(function() {
            notify.update('message', '<strong>No</strong> password was entered upon login.');
            notify.update('type', 'danger');
            notify.update('progress', 100);
        }, 1000);
        $("#password").addClass("has-error");
        setTimeout(function() {
            $.notify({ // options
                icon: 'fa fa-danger',
                message: "Please enter a password to login!"
            },{ // settings
                type: 'danger',
                animate: {
                    enter: 'animated fadeInDown',
                    exit: 'animated fadeOutUp'
                }
            });
        }, 2000);
        return false;
    }
    else if (email == "") {
        setTimeout(function() {
            notify.update('message', '<strong>No</strong> e-mail address was entered upon login.');
            notify.update('type', 'danger');
            notify.update('progress', 100);
        }, 1000);
        $("#email").addClass("has-error");
        setTimeout(function() {
            $.notify({ // options
                icon: 'fa fa-danger',
                message: "Please enter an e-mail address!"
            },{ // settings
                type: 'danger',
                animate: {
                        enter: 'animated fadeInDown',
                        exit: 'animated fadeOutUp'
                }
            });
        }, 2000);
        return false;
    }
    setTimeout(function() {
        notify.update('message', '<strong>Checking</strong> if you have submitted an e-maill address and password.');
    }, 2000);
    setTimeout(function() {
        notify.update('message', '<strong>Succesfully</strong> submitting e-mail address and password for logging in.');
    }, 3000);
    setTimeout(function() {
        notify.update('message', '<strong>Attempting</strong> to login!');
        notify.update('progress', 100);
    }, 4000);
    setTimeout(function () {
        $.ajax({
            type  : "POST",
            url   : '/login',
            data  : formData,
            cache : false,
            success : function() {
                location.reload();
            },
            error : function() {
                alert("Fail");
            }
        });
    }, 4000);
    return false;
});

it seems to be when i have auth.login listener it is causing problems with my ajax login??? any reason why??

Please or to participate in this conversation.