Author Topic: cannot create direct login page  (Read 3267 times)

Offline Pantani

  • Jr. Member
  • **
  • Posts: 18
cannot create direct login page
« on: January 31, 2012, 07:43:38 AM »
I'm using RC 0.7.1 and trying to create a web page, from where I could directly login into RC. My source code is below. This only sends me to the login page and an error appears on the top of the page saying "Invalid request! No data was saved.". This code is copied from logout_redirect/ajax_login, author Roland Liebl. I tried to add the "_task" hidden input element, but did not helped. I've also tried to look into the source code of RC, but after some time I was lost. I also looked at some other code found on google, but it never worked for me. I need a page like this, when after submitting the form, I'm logged in and redirected into RC mail application.

Best regards, Tomas

Code: [Select]

<html>
<body>
<head>
<script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;></script>
</head>
<!-- edit action url -->
<form name=&quot;webmail&quot; action=&quot;http://localhost/roundcubemail/index.php&quot; method=&quot;post&quot;>
    <div class=&quot;info&quot; style=&quot;color:#f00;display:none&quot;></div>

    <input name=&quot;_action&quot; value=&quot;login&quot; type=&quot;hidden&quot; />
    <input name=&quot;_task&quot; value=&quot;login&quot; type=&quot;hidden&quot; />
    <input name=&quot;_timezone&quot; id=&quot;rcmlogintz&quot; value=&quot;_default_&quot; type=&quot;hidden&quot; />
    <input name=&quot;ajax&quot; value=&quot;1&quot; type=&quot;hidden&quot; />
       
    User <input name=&quot;_user&quot; type=&quot;text&quot; value=&quot;my@email.com&quot;/><br />
    Pass <input name=&quot;_pass&quot; type=&quot;password&quot; value=&quot;my_password&quot; /><br />
       
    <input type=&quot;submit&quot;>

</form>

<script type=&quot;text/javascript&quot;>
var d = new Date();
document.getElementById(&quot;rcmlogintz&quot;).value = d.getTimezoneOffset() / -60;
<?PHP
$message = '';
if(isset($_GET['message'])){
  $message = urldecode(trim($_GET['message']));
}
?>
$('div.info').html(&quot;<?PHP echo $message ?>&quot;);
$('div.info').show();
</script>
</body>
</html>

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,882
    • SKaero - Custom Roundcube development
cannot create direct login page
« Reply #1 on: January 31, 2012, 07:58:50 AM »
You'll need to have use a RoundCube plugin to accepted the data to login, take a look at the autologin plugin autologon.php in trunk/plugins/autologon as a reference.

Offline Pantani

  • Jr. Member
  • **
  • Posts: 18
cannot create direct login page
« Reply #2 on: January 31, 2012, 08:50:47 AM »
Thank you, I'm ALMOST there :-)
I simplified the code of the autologon plugin and edit the lines to fit my needs, now I have this (see below). I'm logged in (my url is http://localhost/roundcubemail?_autologin=1&user=myuser&pass=mypass), it's fine, but the server now replies "Server failed! (OK)" and I don't see my messages. Adding $args['host'] and $args['cookiecheck'] in authenticate() function did not helped.

Code: [Select]

class autologon extends rcube_plugin
{
  public $task = 'login';

  function init()
  {
    $this->add_hook('startup', array($this, 'startup'));
    $this->add_hook('authenticate', array($this, 'authenticate'));
  }

  function startup($args)
  {
    $rcmail = rcmail::get_instance();

    if (empty($_SESSION['user_id']) && !empty($_GET['_autologin']))
      $args['action'] = 'login';

    return $args;
  }

  function authenticate($args)
  {
    if (!empty($_GET['_autologin'])) {
      $args['user'] = $_GET['user'];
      $args['pass'] = $_GET['pass'];
      $args['valid'] = true;
    }

    return $args;
  }
}

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,882
    • SKaero - Custom Roundcube development
cannot create direct login page
« Reply #3 on: January 31, 2012, 08:58:04 AM »
You'll also need:
Code: [Select]
$args['cookiecheck'] = false;in the authenticate function. Your also using $_GET but your form is posting the data so it should be $_POST.

Offline Pantani

  • Jr. Member
  • **
  • Posts: 18
cannot create direct login page
« Reply #4 on: January 31, 2012, 09:10:49 AM »
Works! Thank you! :-)
I'm sorry for some things (regarding the "server failed" message) in my previous post, my setup was broken because of previous debugging - I maybe rewrote something in index.php. But works on production server as expected!