Loading...
 
Features / Usability

Features / Usability


Autologin to Ajax chat

posts: 80 Austria

Hi!
I'm quite used to customize tikiwiki, but i wold like to use the existing tiki-login with ajax Chat from blueimp

I don't know how to do it!
The examples for phpBB and the other CMS (here for IPB) are not helping much for tikiwiki, because the ajax chat loses the global variable $user somwhere on the way frown.
The HowTo isn't helping much either.

There are several examples (here for http://sourceforge.net/forum/forum.php?thread_id=2126063&forum_id=774132) but none is helping much for tikiwiki.

I know usually you donb't get helpful answers, but i have to try, since my self modded chat is not scrolling correctly in shitty IE.

Thank you in advance!
Torpedro

posts: 80 Austria

OK, i maanged to integrate the aoutlogin of ajax Chat into tikiwiki, path for ajax chat is tiki/chat:

in custom.php:

Image
require('../tiki-setup.php');


In CustomAJAXChat.php:

Image
// Initialize custom request variables: function initCustomRequestVars() { global $user, $tiki_p_admin, $userlib; include('../lib/userslib.php'); //needed for UserID //echo " tiki_p_admin: " . $tiki_p_admin; // Auto-login tikiwiki users: if(!$this->getRequestVar('logout') && $user != '') { $this->setRequestVar('userName', $user); $this->setRequestVar('userID', $userlib->get_user_id($user)); $this->setRequestVar('userRole', AJAX_CHAT_USER); if ($tiki_p_admin == 'y') { $this->setRequestVar('userRole', AJAX_CHAT_ADMIN); } $this->setRequestVar('login', true); } } // Returns an associative array containing userName, userID and userRole // Returns null if login is invalid function getValidLoginUserData() { $customUsers = $this->getCustomUsers(); //echo "Role: ".$this->getRequestVar('userRole'); if($this->getRequestVar('userName')) { // Check if we have a valid registered user: $userName = $this->getRequestVar('userName'); $userName = $this->convertEncoding($userName, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding')); $userData = array(); $userData['userID'] = $this->getRequestVar('userID'); $userData['userName'] = $userName; $userData['userRole'] = $this->getRequestVar('userRole'); // print_r($userData); return $userData; } return null; }

posts: 80 Austria

A real group mapping can be done also. So you could have chatrooms only available for special tiki groups which are mapped to roles.


Step1: Define additional Roles in config.php

add

Image
define('AJAX_CHAT_GROUP1',5);

before

Image
define('AJAX_CHAT_CHATBOT',4); define('AJAX_CHAT_ADMIN',3);



Step 2: define Chatrooms for the group in users.php and change order to the order in Step1 (so the users and roles have teh same Id, that's important!)

Image
// registered user: $users[1] = array(); $users[1]['userRole'] = AJAX_CHAT_USER; $users[1]['channels'] = array(1,2,3,4,5,6); // moderator user: $users[2] = array(); $users[2]['userRole'] = AJAX_CHAT_MODERATOR; $users[2]['channels'] = array(1,2,3,4,5,6,7,8); // admin user: $users[3] = array(); $users[3]['userRole'] = AJAX_CHAT_ADMIN; $users[3]['userName'] = 'admin'; $users[3]['password'] = 'admin'; $users[3]['channels'] = array(1,2,3,4,5,6,7,8); // 4=chatbot // Tiki Group1 channel definition $users[5] = array(); $users[5]['userRole'] = AJAX_CHAT_GROUP1; $users[5]['channels'] = array(1,2,3,4,5,6,7);



Step3: Map the TikiGroup to the Ajax-chat role in CustomAJAXChat.php, the full code again:

Image
function initCustomRequestVars() { global $user, $tiki_p_admin, $userlib; include('../lib/userslib.php'); //needed for UserID //echo " tiki_p_admin: " . $tiki_p_admin; // Auto-login tikiwiki users: if(!$this->getRequestVar('logout') && $user != '') { $UserId = $userlib->get_user_id($user); $this->setRequestVar('userName', $user); $this->setRequestVar('userID', $UserId); $this->setRequestVar('userRole', AJAX_CHAT_USER); // define default role if ($tiki_p_admin == 'y') { $this->setRequestVar('userRole', AJAX_CHAT_ADMIN); } $user_details = $userlib->get_user_details($user); $ug = $user_details['info']['default_group']; if ($ug == 'TikiGroup1') { $this->setRequestVar('userRole', AJAX_CHAT_GROUP1); } $this->setRequestVar('login', true); } }


and replace

Image
$validChannels = $customUsers[$this->getUserID()]['channels'];


with

Image
$validChannels = $customUsers[$this->getUserRole()]['channels'];

posts: 175 Canada

Hi Torpedro,

Thanks for your work on this. I'm trying to get it working on our tiki as well. I've installed chat and followed your modification instructions as best I could, but still not getting autologin.

Also when I attempt to log in to chat with my tiki credentials, it says invalid username.

1) are you starting with the Ajax Chat 0.8.3 regular stand-alone version?
2) I'm a little unclear about the customAJAXChat file. I've attached it below, does it look like yours?

Thanks,

-Kent