Forums | Mahara Community

Developers /
Added link but need to know username


anonymous profile picture
Account deleted
Posts: 7

06 May 2010, 7:43

Hello,

       I'm trying to customize my mahara.  What I'm wanting to do is add a link that will connect to the users zimbra account.  So when they click the link it automatically logs them into their zimbra.  You can do this with moodle with the php script on this site http://wiki.zimbra.com/wiki/Preauth and changing how you get the username for moodle to $user = "$USER->username";.  I tried to do this with mahara but the change doesn't work for mahara.  How do you get the username through that php script? Thanks

James

anonymous profile picture
Account deleted
Posts: 7

06 May 2010, 15:17

I did a little more digging.  I'm still not 100% sure what $USER->username does but i'm assuming its getting either the POST data from the login form or the $USER variable is a global variable that can point to all the things a user has...username, first name, last name etc...and getting them from the database?  Why doesn't this work for Mahara?  I'm assuming that this is setup the same way in Mahara.  I don't know just thought I would add this in.

anonymous profile picture
Account deleted
Posts: 808

06 May 2010, 16:35

Hi James, try using

$USER->get('username')
anonymous profile picture
Account deleted
Posts: 7

07 May 2010, 7:17

I get this error when I tried the get function

Fatal error: Call to a member function get() on a non-object in /var/www/mahara/zimbra.php on line 19

I see that $USER is setup as a global variable throughout the mahara setup.

Is there a file I need to include with 'require' in my php script that allows me to use the get function to get the ('username').

Below is the script that I used to make moodle work with the link.

<?php
    require_once("./config.php") ;

    //require_login();<------commented out because it gave me some errors with mahara
    /**
    * Globals. Can be stored in external config.inc.php or retreived from a DB.
    */
    $PREAUTH_KEY="";  <------I have this set but removed for security reasons.
    $WEB_MAIL_PREAUTH_URL="http://mail.mydomain.com/service/preauth";
    
    /**
    * User's email address and domain. In this example obtained from a GET query parameter.
    * i.e. [email protected]&domain=domain.com
    * You could also parse the email instead of passing domain as a separate parameter
    */
    //$user = $_GET["user"];
    //$domain=$_GET["domain"];
       
    $user = "$USER->username";<------worked with moodle
    //$user = $USER->get('username');<-----tried this and get the error stated above
    //$user = $_REQUEST['login_username'];<----tried getting the post info from form on login page
    $domain = "dns.mydomain.com";
    $email = "{$user}@{$domain}";

    if(empty($PREAUTH_KEY)) {
        die("Need preauth key for domain ".$domain);
    }
    
    /**
    * Create preauth token and preauth URL
    */
    $timestamp=time()*1000;
    $preauthToken=hash_hmac("sha1",$email."|name|0|".$timestamp,$PREAUTH_KEY);
    $preauthURL = $WEB_MAIL_PREAUTH_URL."?account=".$email."&by=name&timestamp=".$timestamp."&expires=0&preauth=".$preauthToken;
    
    /**
     * Redirect to Zimbra preauth URL
     */
    header("Location: $preauthURL");
?>

anonymous profile picture
Account deleted
Posts: 808

09 May 2010, 22:47

Hi James,

Moodle and Mahara are very different.  You'll find that most Moodle functions and variables don't exist in Mahara at all (e.g. require_login).  Sometimes there will be a Mahara function or variable with the same name as a Moodle one, but it will behave quite differently (e.g. $USER).

If you have a look at the code for some of the other Mahara pages you'll see what you need to do to set up globals like $USER (usually you need to include init.php).

R.

anonymous profile picture
Account deleted
Posts: 7

10 May 2010, 9:22

Ok i've scrapped the idea of linking to zimbra from mahara.  I've decided to create a portal page that someone will login to and there will be buttons that they can click that will take them to Zimbra, Moodle, or Mahara.  This was pretty easy for zimbra and moodle and got them working fine.  Having some difficulty with Mahara.  Is what I did is I took the username and password from the initial login and posted them to the next page.  I then create a form with hidden values that are populated with the respective username and password to use for authentication to the other sites.  The user clicks the button and and the info is sent to the sites to log them in.

Any ideas on how to do this with Mahara.  I see the login page posts the form to itself so how can I bypass the login screen with the inputed values to authenticate the user?

Thanks

anonymous profile picture
Account deleted
Posts: 7

11 May 2010, 7:43

In other words what I'm lookin for is what exactly happens when you click the login button.  What functions are called, values set, so that I can figure out what I need to do to set the appropriate values to log the user on.  Its really difficult to follow the code because there isn't a lot of comments and documentation that I've found to explain what exactly goes on.  Not trying to be mean but the coding is above my level and its hard for me to understand.

A post by Account deleted was deleted

8 results