Roundcube Community Forum


Capture user data at login and logout

Started by dkemens, September 05, 2023, 05:29:44 AM

Previous topic - Next topic


HI all,

I'm developing a simple plugin that sends audit data to an external server on login and logout. There are a handful of items I need (primarily, username) and some that would be "nice to have" (password, though I imagine this is one-way encrypted). The problem is, I can't seem to access the user data at all. I suspect I'm doing something wrong, but I'm relatively new to roundcube and not exactly sure what it is I'm missing. Take this bit of code from my plugin:

    public function init() {
        $this->add_hook('ready', [$this, 'sendAuditLogin']);
        $this->add_hook('session_destroy', [$this, 'sendAuditLogout']);

    public function sendAuditLogin() {
        $rcmail = rcmail::get_instance();
        $user = $rcmail->user;
        $identity = $user->get_identity();
        var_dump($user); // Is an object, but contains no useful information
        var_dump($identity); // This is null
        var_dump($_SESSION); // Contains some items, but nothing pertaining to the user

Futhermore, I'm a bit concerned that if I did get this working, the "session_destroy" hook wouldn't be very useful to me if the user is already gone by then. If that's the case, is there another hook that would be more appropriate to use or should I look into triggering this via javascript in the theme?



Ah! I'll give the logout_after hook a try. I had originally started with the login_after hook and was getting nowhere (even though it explicitly states the user info should be available) - so I moved to the 'ready' hook - but it's possible I got my wires crossed between CI pipelines. I'll give it another go.