Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: aweirig on October 21, 2008, 09:39:14 AM

Title: login and redirect to compose page
Post by: aweirig on October 21, 2008, 09:39:14 AM
Hello,

I'm trying to achieve to following transition into RC.

Users login (userid + password) to our website.
Somewhere on our site they find links to send emails to given adresses.

When the user clicks on such a link, I would like to log the user into RC and direct him to the compose page showing a prepared email template (prefilled to, cc, bcc, subject, body etc),

I can achieve both goals individually, i.e. I know how to log the user into RC using a standard form or even by passing the userid + password in the URL and slightly changing index.php to accept parameters from URL.
I can also build a URL with _task=mail&_action=compose&...... to show the compose page ONCE the user is logged into RC.

But currently I can't find a way to achieve both actions in "a single step".

Any help is greatly appreciated.

Alex
Title: login and redirect to compose page
Post by: rosali on October 21, 2008, 10:24:03 AM
I do not see the sense why you want to do this with RoundCube. There are lots of form mailer scripts which are much more suiteable for your purpose (f.e.: Class: sendmail (sendmail) - PHP Classes (http://www.phpclasses.org/browse/package/490.html))
Title: login and redirect to compose page
Post by: aweirig on October 22, 2008, 02:09:07 AM
Hi,

thanks for answering my post.

I agree with you and I know about those classes but in this very specific situation people must send those emails from their personal mailbox (i.e. the send email must show up in the Sent Items), the identity of the sender must be "guaranteed" through the mail client.

We need this in an Intranet solution and have an obligation to work like this.

I have done using Squirrelmail but I'm not too eager on using SM, I prefer RC but if RC can't be changed to support our needs, I'll have to go back to SM.

Alex
Title: login and redirect to compose page
Post by: CarlB on June 18, 2009, 01:15:22 AM
I doubt Alex will see this seven months later but...

It can be done.

I am working on the same kind of thing and found this:

Roundcube login via PHP script : Yet another web log (http://blog.philippheckel.com/2008/05/16/roundcube-login-via-php-script/)

you can change the redirect() redirect code to something like:

$sendto = $_GET['sendto'];

$rcl->redirect("?_task=mail&_action=compose&_to=$sendto");


I can get this script to meet my needs, but only when using clear text password! I can only pull my mail sites user name and a MD5 of the password from a cookie...
Title: login and redirect to compose page
Post by: rosali on June 19, 2009, 02:04:22 AM
By default RC does not store the password, not even an md5 hash of the password. The encrypted password is only available during a valid RC session.

Perhaps I will write a plugin for RC 0.3 to store an md5 hash of the password in the user_prefs database field.

Meanwhile you have to use the weak plain text method.
Title: login and redirect to compose page
Post by: rosali on June 21, 2009, 07:07:55 AM
Here is a plugin to get user's password.

You get the md5 hash of the password by ...

$hash = md5(savepassword::getpw("[email protected]"));


Plugin code (folder name "savepassword")


/**
 * Save password plugin
 *
 *
 * @version 1.0 - 21.06.2009
 * @author Roland 'rosali' Liebl
 * @website http://dl.roland-liebl.de/RoundCube/plugins/savepassword
 * @licence GNU GPL
 *
 *
 **/
 
/** USAGE
 *
 * #1- Alter RoundCube Database table `users`:
 *
 *     ALTER TABLE `users` ADD `password` TEXT NULL AFTER `last_login` ;
 *
 * #2- Register plugin ("./config/main.inc.php ::: $rcmail_config['plugins']").
 * #3- Get the password when user is not logged in:
 *    
 *     $password = savepassword::getpw("[email protected]");
 *
 **/
 
class savepassword extends rcube_plugin
{

    function init()
    {
        $this->add_hook('login_after', array($this, 'savepw'));
    }

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

        if($_SESSION['user_id']){ // user has been authenticated successfully
          $query = "UPDATE `".get_table_name('users')."`
                SET  password=?
                WHERE user_id=?;";
                 
          $ret = $rcmail->db->query($query,$_SESSION['password'],$_SESSION['user_id']);
       
        }

        return $args;
    }
   
    function getpw($username){
   
        $rcmail = rcmail::get_instance();    
   
        $rcmail->db->query("
                SELECT * FROM ".get_table_name('users')."
                WHERE  username=?",
                $username);
           
        $user = $rcmail->db->fetch_assoc();
       
        if(isset($user['password'])){
          return $rcmail->decrypt($user['password']);
        }
        else{
          return false;
        }
    }

}

?>