1. This sub-forum relates to Kayako 3, which is now end-of-life. Please be aware that a lot of information relating to features, sales and the roadmap in the Kayako 3 forums is now outdated or defunct (no longer applicable).

    If unsure about anything, please create a new thread or contact us.

    You can visit the main forums for the latest Kayako here.

loginshare imap

Discussion in 'LoginShare' started by snuffop, Feb 23, 2008.

  1. snuffop

    snuffop New Member

    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;
    
    }
    ?>
     
  2. craigbrass

    craigbrass New Member

    Nice share snuffop!
     
  3. rkjones

    rkjones New Member

    No Name on IMAP LoginShare

    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
     
  4. rkjones

    rkjones New Member

    Found the blank name issue. Add:

    in the templates.php file in addition to the other code changes mentioned. I stuck mine in the "LOGINSHARE" section.

    Kyle
     
  5. Andres Berdugo - Dewak

    Andres Berdugo - Dewak Experienced Member

    Excellent I think this LoginShare should come out of the box in V4
     
  6. Andrew Scott

    Andrew Scott Established Member

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

    Andrew, Holbi
     
  7. Bryson Braden

    Bryson Braden New Member

    As pace of development of Version 4 increases, it is important that we hear what you want to see in the next major product release. We want to know what is working for you, what isn't working for you and what you are missing.
     

Share This Page