Author Topic: Capture user data at login and logout  (Read 6226 times)

Offline dkemens

  • Newbie
  • *
  • Posts: 5
Capture user data at login and logout
« on: September 05, 2023, 05:29:44 AM »
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:

Code: [Select]
    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?

Thanks!!

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,878
    • SKaero - Custom Roundcube development

Offline dkemens

  • Newbie
  • *
  • Posts: 5
Re: Capture user data at login and logout
« Reply #2 on: September 05, 2023, 10:13:06 AM »
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.