Author Topic: First plugin, interacting with hook authenticate / login_failed  (Read 4396 times)

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
First plugin, interacting with hook authenticate / login_failed
« on: November 16, 2014, 06:40:42 PM »
Hi forum!

I'm at the first plugin with hooks implementation.

I my goal is to interact with user login, so I started with the very unuseful code below, just to try if something works.

I'm using Roundcube 1.0.3

Here is the code:

Code: [Select]
class login_additional_controls extends rcube_plugin
{
public $task = 'login';

function init()
{
$fp = fopen('/tmp/login_additional_controls.log', 'w');

fwrite($fp, "---------------------- init ----------------------\n");

fclose($fp);

$this->add_hook('authenticate', array($this, 'during_login'));
$this->add_hook('login_failed', array($this, 'after_login_failure'));
$this->add_hook('login_after', array($this, 'after_login_success'));
}

function during_login($data)
{
  $data['abort'] = true;
  $data['error'] = 'Something wrong is happening';

return $data;

}

function after_login_failure($data)
{

}

function after_login_success($data)
{

}

}

I think that at this very initial stage the plugin should block any login (with right or wrong credentials) attempt, with the  return message "Something wrong is happening" on the login page (according to the Plugin_hooks page:
Quote
error: if using abort, also set error to any string (else you will get a storage error)
).

What is really happening is that every login attempt fails (that is right) but the error message is always the same "Login failed." (that is unexpected).

Did I misunderstood the hook specifications? How can I resturn my custom error message?

Thanks in advance for you help!

Offline alec

  • Hero Member
  • *****
  • Posts: 1,365
Re: First plugin, interacting with hook authenticate / login_failed
« Reply #1 on: November 17, 2014, 03:24:44 AM »
This is not possible, https://github.com/roundcube/roundcubemail/blob/release-1.0/index.php#L159. I think you could try to overwrite the message from login_failed hook:

$RCMAIL->output->show_message($your_error_message, 'warning');

Offline marco-shagrat

  • Jr. Member
  • **
  • Posts: 10
Re: First plugin, interacting with hook authenticate / login_failed
« Reply #2 on: November 17, 2014, 03:40:23 AM »
Wow,
  thanks for you answer.

Your solution is working!

Thank you very much!