Kayako logo
Modifications & Addon Releases Modification guides and addons are posted here to share with the community. Do not post requests in here!

Notices

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  (#1) Old
snuffop Offline
New Member
 
Posts: 1
Join Date: Feb 2008
Wink loginshare imap - 23-02-2008, 05:14 AM

I still cannot believe no one else has created this already, and if they have and I didn't find it sorry for the dupe... Anyway I needed to get our customers authenticated to kayako and our most common denominator is email.. they all have an email account. and there were no built in Imap loginshare modules. well I'm posting the file hack I made to the default loginshare module with pieces of code from other examples in this forum.. Hope it's helpful for Others.

Create the below file as imap.login.php into the includes/loginShare directory of your installation

Be sure to edit the includes/loginShare/loginshare.config.php file and put

Code:
define("LOGINAPI_IMAP", 240);
and

Code:
$_LOGINAPI[LOGINAPI_IMAP] = array("title" => $_SWIFT["language"]["loginapi_imap"], "include" => "imap.login.php");
in respective sections

also modify the locale/en-us/templates.php file and add
Code:
    'imapserver' => 'IMAP Server Name',
    'imapport' => 'Port (Default: 143)',
    'imapprefix' => 'Prefix (Default: INBOX)',
somewhere in the __Lang array probably near the //loginshare comment tag but as long as it makes it into the array.

Use like any other loginshare add your imap server name and port etc in the templates section of the admin. if the imap login fails or if the user happens to not have an email account and registers to kayako it will attempt to auth via the defaut kayako DB..



Code:
<?php
/**
*    Imap Login Module for Kayako 3.11.01
*    By Marty Buchaus mbuchaus@asimail.com
*      ASI Technologies 2008
*
**/

if (!defined("INSWIFT")) {
    trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Initialization function. You can connect to your database etc over here.
*/
function loginShareInit(){
    global $loginshare;
    $loginshare->moduleloaded = true;
}

/**
* Authorize a user based on email and password
*/
function loginShareAuthorize($username, $password){

    global $dbCore, $_SWIFT, $loginshare, $settings, $cookie;
    
    $_loginshare = $settings->getSection("loginshare");
    
    $serverinfo = sprintf("{%s:%s/service=imap/notls/novalidate-cert}%s", $_loginshare['imapserver'], $_loginshare['imapport'], $_loginshare['imapprefix']);

    $conn = @imap_open($serverinfo, $username, $password, OP_HALFOPEN);

    if (is_resource($conn)){
        $userid = getLoginShareUser(LOGINAPI_IMAP, $username);
        $regpassword = substr(buildHash(),0,8);
        if (!$userid){
            // Not registered, Register him
            $userid = insertUser(true, $username, $regpassword, $_SWIFT["tgroup"]["regusergroupid"], LOGINAPI_IMAP, $username, '', $_SWIFT["tgroup"]["languageid"], 0, false, 1, true);
        }
        if (!$userid){
            return false;
        }
        $_swiftuser = $loginshare->loadSWIFTUser($userid);
        if (!$_swiftuser){
            return false;
        }
        $_SWIFT["user"] = $_swiftuser;
        return $_swiftuser["userid"];
    } else {
        //print_r($e->getmessage());    
        // Get the user id associated with this email
        $_email = $dbCore->queryFetch("SELECT `userid` FROM `". TABLE_PREFIX ."useremails` WHERE `email` = '". $dbCore->escape($username) ."';");
        if (empty($_email["userid"])){
            return false;
        }
        $_user = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."users` WHERE `userid` = '". intval($_email["userid"]) ."';");
        $loginmod = false;
        $_cookieset = $cookie->getSCookie("loginemail");
        if(!empty($_cookieset)){
            $password_chk = $password ;
        }else{
            $password_chk = md5($password);
        }
    
        if ($_user["userpassword"] == $password_chk && $_user["enabled"] == 1 ){
            // Authenticated
            $_SWIFT["user"] = $_user;
            return $_user["userid"];
        } else {
            unset($_SWIFT["user"]);
            return false;
        }    
    }
    return false;
}

/**
* Return the Unique User ID of the current user
*/
function loginShareUserID()
{
    global $_SWIFT;

    if (empty($_SWIFT["user"]["userid"]))
    {
        return false;
    } else {
        return $_SWIFT["user"]["userid"];
    }
}

/**
* Logout the current user
*/
function loginShareLogout()
{
    global $session, $_SWIFT;

    $session->updateSession($_SWIFT["session"]["sessionid"], 0);

    return true;
}

/**
* Load the user credentials into current workspace. The following variables should be declared for proper working:
* userid - User id that is set in the "users" table
* fullname
* email - Array
* password (MD5 Hashed)
* usergroupid - If this is not set, then it will use the default registered user group for this template group
*/
function loginShareLoadUser()
{
    global $dbCore, $_SWIFT, $loginshare;

    if (empty($_SWIFT["session"]["typeid"]))
    {
        $_SWIFT["user"]["loggedin"] = false;
        return false;
    }

    $_user = $loginshare->loadSWIFTUser($_SWIFT["session"]["typeid"]);
    if (!$_user)
    {
        $_SWIFT["user"]["loggedin"] = false;

        return false;
    }

    $_SWIFT["user"] = $_user;

    return true;
}

/**
* Renders the Login Share Form
*/
function renderLoginShareForm()
{
    global $_SWIFT;

    $forms = array();

    $forms[0]["title"] = $_SWIFT["language"]["imapserver"];
    $forms[0]["name"] = "imapserver";
    $forms[1]["title"] = $_SWIFT["language"]["imapport"];
    $forms[1]["name"] = "imapport";
    $forms[2]["title"] = $_SWIFT["language"]["imapprefix"];
    $forms[2]["name"] = "imapprefix";


    return $forms;

}
?>
   
Reply With Quote
  (#2) Old
craigbrass Offline
Senior Member
 
Posts: 5,401
Join Date: Jun 2005
Location: Cumbria, UK
23-02-2008, 10:17 AM

Nice share snuffop!


Craig Brass - Kayako Forum Squatter (Note: I am NOT a staff member)

Icon Headquarters - Its Elixir - Web2Messenger
   
Reply With Quote
  (#3) Old
rkjones Offline
New Member
 
Posts: 2
Join Date: Jun 2008
No Name on IMAP LoginShare - 11-06-2008, 05:22 PM

Hi snuffop,

This sounds like exactly what I need, but I can't seem to get it working for me.

When I make the edits, I get a new item under LoginShare, but the item has no name. In other words, I get a new icon, but, unlike, say, Viper Cart, there's no name next to the icon.

Also, I can't seem to get users to authenticate using the module. I'm on a shared host, so the username is in the format of username@domain.com. Could this be the issue?

Kyle
   
Reply With Quote
  (#4) Old
rkjones Offline
New Member
 
Posts: 2
Join Date: Jun 2008
11-06-2008, 05:44 PM

Found the blank name issue. Add:

Quote:
'loginapi_imap' => 'IMAP Login',
in the templates.php file in addition to the other code changes mentioned. I stuck mine in the "LOGINSHARE" section.

Kyle
   
Reply With Quote
  (#5) Old
Dewak Offline
Member
 
Dewak's Avatar
 
Posts: 129
Join Date: Feb 2008
11-06-2008, 08:04 PM

Excellent I think this LoginShare should come out of the box in V4


Andres Berdugo
Email & MSN: andres[at]dewak.com
Skype: andres.dewak
Dewak: Kayako Development, Consultancy and Support
http://www.dewak.com
   
Reply With Quote
  (#6) Old
Andrew Scott Offline
Member
 
Andrew Scott's Avatar
 
Posts: 142
Join Date: Apr 2008
Location: Swindon, UK
11-06-2008, 10:06 PM

Yes, this is really nice solution. Good work. I do agree with Andres, this loginshare should be a part of Kayako v4

Andrew, Holbi


Andrew Scott
kayako]at[holbi.co.uk
Kayako Development Manager
Holbi Kayako development

   
Reply With Quote
Reply

Tags
imap, loginshare

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kayako WHMCS LoginShare Module Explovision Offers 15 04-12-2007 01:31 PM
Unable to Compile PHP with IMAP support Aaron Technical Chat 2 06-09-2007 07:31 PM
LoginShare issues? threeyears SupportSuite, eSupport and LiveResponse 5 21-11-2006 02:17 PM
IMAP, IMAP SSL , e-mails questions gerardo SupportSuite, eSupport and LiveResponse 0 11-05-2006 04:34 PM



Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vBulletin Skin developed by: vBStyles.com


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46