cancel
Showing results for 
Search instead for 
Did you mean: 

cometchat integration with share

pwjepson
Champ in-the-making
Champ in-the-making
Hello,

we are trying to implement cometchat (text and peer-to-peer video chat) within the share website. cometchat is in PHP, so we have a separate server running apache and PHP to accommodate.

cometchat connects to the alfresco mysql database directly to get user names and adds a few tables to manage their side of things. there are two lines of code required in the alfresco share site header, so we added them to header.get.head.ftl. (its just a stylesheet link and a single php file with their own js code to drop the chat bar into the footer of every page.)

we can now see the chat bar when users log in, but we cannot figure out how to get cometchat to recognize who is logged in.

We need to be able to provide a session variable or cookie with the user name from alfresco to cometchat so they will know who is logged in. Is there any way to create that? the examples they give all relate to php, but i was wondering if we could create a cookie with javascript and then read that data from the cometchat side? i have attached their instructions for reference. if we can get this working i would gladly post a step-by-step tutorial so others can use this too. I believe it could be a very useful add-on.

thanks in advance!

CometChat Update single-sign-on functionality

Scroll down to find the getUserID() function.

The getUserID() function is used to return the logged in user’s ID. Depending on how you have programmed your site, you will have to find out the user’s ID.

If you have written a simple PHP authentication, then during the authentication, you can specify a session variable like:

/* In your own login.php */
/* After you authenticate the user */
$_SESSION['userid'] = $users['id']; // Modify to suit requirements
Then your getUserID() function will look like:

function getUserID() {
    $userid = 0; // Return 0 if user is not logged in

    if (!empty($_SESSION['userid'])) {
        $userid = $_SESSION['userid'];
    }

    return $userid;
}
If you are using a cookie then read that using the following function:

function getUserID() {
    $userid = 0; // Return 0 if user is not logged in

    if (!empty($_COOKIE['userid'])) {
        $userid = $_COOKIE['userid'];
    }

    return $userid;
}
If you are using a more complex method of authentication like storing the session_hash in the database, then your getUserID() function will look something like:

function getUserID() {
    $userid = 0; // Return 0 if user is not logged in

        if (!empty($_COOKIE['sessionhash'])) {
        $sql = ("select userid from ".TABLE_PREFIX."session
            where sessionhash = '".mysql_real_escape_string($_COOKIE['sessionhash'])."'");
        $query = mysql_query($sql);
        $session = mysql_fetch_array($query);
        $userid = $session['userid'];
        }

    return $userid;
}
2 REPLIES 2

pwjepson
Champ in-the-making
Champ in-the-making
I have been working with cometchat support and they claim if i use a cookie with the userid from the alf_authority table, it will work.

so, can anyone explain how I can get the following to work and in which alfresco share file I should use it?


<script>
var userid='USERID'; //this is where I cannot figure out how to populate USERID with the proper information from alf_authority for the logged in user
document.cookie="cc_data="+userid;
</script>

I see in login.jsp that the userid is actually the user name, but if i change any code in that file it just breaks alfresco share.

if this is complicated, please just tell me and I will try to find a programmer to help me. I was hoping its just one line of code to grab the USERID and make a cookie.

any help would be appreciated, Thanks!

mrogers
Star Contributor
Star Contributor
I've moved your topic into the Share Development forum.

The userId is available in Share, you should be able to run a small piece of JavaScript to retrieve it.   I suggest you look at how the other applets within Share work.