1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Connecting / Sharing with Login details from another website

Discussion in 'Installation and General Troubleshooting' started by tktushonline, Mar 8, 2012.

  1. tktushonline

    tktushonline New Member

    Hi
    My question is

    Can I connect our other website which is made in Joomla with the one in Hotaru, by allowing users on both sites to login on any of the site with their username & password?

    I need to connect to databases & its tables... but how?

    Can someone guide me?
    Thanks...
     
  2. frytec

    frytec Member

    Well, we dont have a plugin for that.

    I use SMF and Hotaru integrated, both are on same database, with different prefix_.

    I only allow users to register via Hotaru registration form, the SMF registration is disabled.

    I changed the Hotaru registration plugin, to, after users registers in Hotaru, it will insert the user details to the SMF users table via SQL.

    If you want both registrations working, you will need make the SQL insert in the two ways.

    That solves the issue integrating both users tables, but to make them synchronized you will need to work with sessions and cookies, and thats more complex.
     
  3. AceKnight21

    AceKnight21 New Member

    Frytec,

    From what I've seen on these forums in my time (unless I've just not noticed it) there are a lot of people that would like to know how to integrate any forum with Hotaru. Could you possibly explain how to do this?
     
  4. frytec

    frytec Member

    ace, thats the actual situation:

    we DONT have any plugin to intagrate with any forum.

    the developer of miniBB forum wants 100USD to build a hotaru plugin to integrate and synchronize miniBB with Hotaru.
    im trying to find a group of people interested in help to pay it. thats the topic:
    http://forums.hotarucms.org/showthread.php?1863-Synchronization-with-miniBB-forum

    The SMF forum, have a nice forum API, called smf2api, wich will let you control SMF from Hotaru (or any other system).
    and they have a integration hook aswaell, wich will let you control Hotaru (or any other system) from SMF.
    this is the related topic:
    http://www.simplemachines.org/community/index.php?topic=453008.0

    In my hotaru site, i use this API to control and synchronize Hotaru login, logout, and registrarion with my SMF forum.

    you can see it working here
    http://www.catalink.com.br/forum/

    Try registering, login in, and go to the forum link, you will see you already logged in forum.
    Logout via hotaru logout, go to the forum link, and you will see yourself logged of the forum.

    If you are logged of, and go to the forum link, the forum will ask you for registration or login, if you click any of those links, they will head you to the hotaru registration form, or hotaru login form.

    Thats what im doing and its working ok, but the real good solution would be pay the developer of miniBB for a more stable and dedicated plugin.
     
  5. AceKnight21

    AceKnight21 New Member

    That seems to work well enough. I understand that it's not exactly a plugin type solution though. I guess I'm going to get to work on setting this up for my site now as it seems like it might work perfectly for my needs.
     
  6. frytec

    frytec Member

    Ok, assuming you have the Hotaru in the root folder and SMF in the /forum/ subfolder, and both uses the same database, SMF uses forum_ prefix and Hotaru uses hotaru_ prefix.

    The smf2api.php should be placed in /forum/

    First thing you must notice is that i do not use the API registration feature (could not make it work yet, but it can be done and it is in my to do list), so im using an SQL Trigger to copy the new user details from hotaru users table to SMF users table. Since the password is hashed, it will gona be copied via inline SQL upon the new registration is done, not via SQL trigger. You must sucessfully create this trigger in your DB to make registration 'hack' works.

    Code:
    DELIMITER $$
    CREATE TRIGGER forumReg
    AFTER INSERT ON hotaru_users 
    FOR EACH ROW
    BEGIN
      DECLARE regDate INT;
      SET @regDate = (SELECT UNIX_TIMESTAMP(NEW.user_date));
      INSERT INTO forum_members (id_member, member_name, email_address, real_name, is_activated, date_registered)
      VALUES (NEW.user_id, NEW.user_username, NEW.user_email, NEW.user_username, 0, @regDate);
    END
    $$
    DELIMITER ;
    Explaining this trigger a little, right after a new user registration is successfully inserted in hotaru users table, this trigger set the following fields in the SMF users table:

    user_id (the user id will be the same in hotaru and SMF, thats a little trick i made to make administration easier.)
    user_username (the username as is in hotaru users table)
    user_email (the user email as is in hotaru users table)
    real_name (the SMF real name and username is the same, as is in hotaru users table)
    the 0 sets the is_activated to false, that means the user is pending email confirmation, wich will be done via hotaru confirmation email. When user click the confirmation link, the is_activated value is set to 1, that means user is now activated in SMF (I will explain how to do this in a while)
    @regDate (the date user registered in hotaru. Hotaru uses common timestamp, SMF uses unix_timestamp, so this is converting the value to unix_timestamp)

    Second thing, is that you have to disable the SMF registration, and change the SMF login/register links to make them point to you hotaru login/register. Its an easy change, if you have any issue with that tell me.

    Now, in hotaru /content/plugins/user_signin/user_signin.php

    you will have to find the function public function theme_index_top($h) and add those lines below in the right place

    this line calls the API.
    require_once ('./forum/smf_2_api.php');

    this line logs out the user.
    smfapi_logout();

    this line logs in the user.
    smfapi_login($username);

    these two lines saves the user password to the SMF users table via SQL, as explained above.
    $sql = "UPDATE forum_members SET passwd = ".$password." WHERE member_name = %d";
    $h->db->query($h->db->prepare($sql, $username));


    (check my function and you will find the place to insert each of those lines).

    Code:
        public function theme_index_top($h)
        {
           $username = $h->cage->post->testUsername('username');
           $password = $h->cage->post->testPassword('password');
           $email = $h->cage->post->testEmail('email');  
           require_once ('./forum/smf_2_api.php');
    
            switch ($h->pageName)
            {
                case 'logout':
                    smfapi_logout();
                    $h->currentUser->destroyCookieAndSession();
                    header("Location: " . BASEURL);
                    exit;
                    break;
                case 'login':
                    $h->pageTitle = $h->lang["user_signin_login"];
                    $h->pageType = 'login';
                    if ($this->login($h)) { 
                        // success, return to front page, logged IN.
                        $return = str_replace('&', '&', $h->cage->post->getHtmLawed('return'));
                        if ($return) {
                            header("Location: " . $return);
    
                        } else {
                            header("Location: " . BASEURL);
                        }
                        smfapi_login($username);
                        die(); exit;
                    } 
                    break;
                case 'register':
                    $h->pageTitle = $h->lang["user_signin_register"];
                    $h->pageType = 'register';
                    $user_signin_settings = $h->getSerializedSettings('user_signin');
                    $h->vars['useRecaptcha'] = $user_signin_settings['recaptcha_enabled'];
                    $h->vars['useEmailConf'] = $user_signin_settings['emailconf_enabled'];
                    $h->vars['regStatus'] = $user_signin_settings['registration_status'];
                    $h->vars['useEmailNotify'] = $user_signin_settings['email_notify'];
    
                    $userid = $this->register($h);
                    if ($userid) { 
                        // success!
    
            $sql = "UPDATE forum_members SET passwd = ".$password." WHERE member_name = %d";
            $h->db->query($h->db->prepare($sql,  $username));
    
                        if ($h->vars['useEmailConf']) {
                            $h->vars['send_email_confirmation'] = true;
                            $this->sendConfirmationEmail($h, $userid);
                            // fall through and display "email sent" message
    
                        } else {
                            // redirect to login page
                            header("Location: " . BASEURL . "index.php?page=login");
                            die(); exit;
                        }
                    }
                    break;
                case 'emailconf':
                    $h->pageTitle = $h->lang['user_signin_register_emailconf'];
                    $h->pageType = 'register';
                    break;
            }
        }

    Now, to synchronize the hotaru user confirmation and SMF user confirmation you will have to find the function public function checkEmailConfirmation($h)

    and add the these two lines

    $sql = "UPDATE forum_members SET is_activated = 1 WHERE member_name = %d";
    $h->db->query($h->db->prepare($sql, $username));


    as you did before, check my function below and find the right place to add those lines.


    Code:
        public function checkEmailConfirmation($h)
        {
            $user_id = $h->cage->get->getInt('id');
            $conf = $h->cage->get->getAlnum('conf');
            
            $user = new UserAuth();
            $user->getUser($h, $user_id);
            
            if (!$user_id || !$conf) {
                $h->messages[$h->lang['user_signin_register_emailconf_fail']] = 'red';
            }
            
            $sql = "SELECT user_email_conf FROM " . TABLE_USERS . " WHERE user_id = %d";
            $user_email_conf = $h->db->get_var($h->db->prepare($sql, $user_id));
            
            if ($conf === $user_email_conf) 
            {
                // update role:
                $user->role = $h->vars['regStatus'];
                
                $h->pluginHook('user_signin_email_conf_post_role');
    
                // update user with new permissions:
                $new_perms = $user->getDefaultPermissions($h, $user->role);
                unset($new_perms['options']);  // don't need this for individual users
                $user->setAllPermissions($new_perms);
                $user->updatePermissions($h);
                $user->updateUserBasic($h);
            
                // set email valid to 1:
                $sql = "UPDATE " . TABLE_USERS . " SET user_email_valid = %d WHERE user_id = %d";
                $h->db->query($h->db->prepare($sql, 1, $user->id));
                
                // notify chosen mods of new user by email:
                if (($h->vars['useEmailNotify'] == 'checked') && (file_exists(PLUGINS . 'users/libs/UserFunctions.php'))) {
                    require_once(PLUGINS . 'users/libs/UserFunctions.php');
                    $uf = new UserFunctions();
                    $uf->notifyMods($h, 'user', $user->role, $user->id);
                }
            
                $success_message = $h->lang['user_signin_register_emailconf_success'] . " <br /><b><a href='" . $h->url(array('page'=>'login')) . "'>" . $h->lang['user_signin_register_emailconf_success_login'] . "</a></b>";
                $h->messages[$success_message] = 'green';
    
    // Forum Activation
            $sql = "UPDATE forum_members SET is_activated = 1 WHERE member_name = %d";
            $h->db->query($h->db->prepare($sql,  $username));
    
            } else {
                $h->messages[$h->lang['user_signin_register_emailconf_fail']] = 'red';
            }
                
            return true;
        } 
    And thats all.
     
    Last edited: Mar 13, 2012
    AceKnight21 likes this.

Share This Page