Roundcube Community Forum

 

First plugin, interacting with hook authenticate / login_failed

Started by marco-shagrat, November 16, 2014, 06:40:42 PM

Previous topic - Next topic

marco-shagrat

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:


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:
Quoteerror: 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!

alec

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');

marco-shagrat

Wow,
  thanks for you answer.

Your solution is working!

Thank you very much!