AppGini 5.70 – Authentication logging

Out of the box, AppGini does not provide logging of user authentication attempts.  For some of my projects, I do need to track who logs on when.  Using the hooks feature, I put the following code together that will log who has logged on (and who hasn’t).

Edit the hooks/__global.php file, and add the following function.

function logit ($memberInfo,$status)
{
   if(!sql('select 1 from tbl_logs',$e))
   {
      sql('create table tbl_logs (id integer auto_increment primary key,username varchar(100), datetime datetime,status varchar(100),ip varchar(30))',$e);
   }
   sql('insert into tbl_logs (username,datetime,status,ip) values(\'' . makeSafe($memberInfo['username']) . '\',CURRENT_TIMESTAMP,\'' . makeSafe($status) . '\',\'' . makeSafe($memberInfo['IP']) . '\')',$e);
   return '';
}

Now edit the two functions below, and add a link the procedure above.

function login_ok($memberInfo, &$args){
   logit($memberInfo,'success');
   return '';
}
 
function login_failed($attempt, &$args){
   logit($attempt,'failed');
   return '';
}

And that should be it. The next time someone logs on (or tries to log on), a new table (tbl_logs) will be created with the details of who has logged on.

Tags:

About: massyn


2 thoughts on “AppGini 5.70 – Authentication logging”

  1. I tried this but get an error when logging in.

    The table ‘appgini.tbl_logs’ doesn’t exist.
    Query:
    select 1 from tbl_logs
    The above info is displayed because you are currently signed in as the super admin. Other users won’t see this.
    You could try fixing this issue from the Admin Area : Utilities menu : Rebuild Fields.

    Using WAMPServer 2.5 with MySQL 5.6.17

  2. I went ahead and modified the logit function and it’s working now.

    function logit ($memberInfo,$status)
    {
    sql(‘create table if not exists tbl_logs (id integer auto_increment primary key,username varchar(100), datetime datetime,status varchar(100),ip varchar(30))’,$e);
    sql(‘insert into tbl_logs (username,datetime,status,ip) values(\” . makeSafe($memberInfo[‘username’]) . ‘\’,CURRENT_TIMESTAMP,\” . makeSafe($status) . ‘\’,\” . makeSafe($memberInfo[‘IP’]) . ‘\’)’,$e);
    return ”;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.