UserApplePie / UserApplePie-v4

UserApplePie v4 User Management System MVC Framework CMS PHP MySQL
https://www.userapplepie.com
16 stars 7 forks source link

Question: multi-domain #43

Closed sollidius closed 7 years ago

sollidius commented 7 years ago

Hey,

I was looking for a simple CRM, and UAP seems neat! However, I have one question of concern. I have multiple domain names and want to use UAP on all of them (on same local install of course) Is this possible? (sort of SSO thingie) or is there an issue with session variables and other stuff? Or could this issue be solved by letting all domains use the same virtualhost and use PHP to determine which domain is used and which stuff to show?

sollidius commented 7 years ago

I noticed it not working at the moment due to cookies. Would it be possible if I would let it set cookies for all domains at once? Like with a setcookie.php file and add HTML to get setcookie.php from all domains?

davarravad commented 7 years ago

I have not tested this personally. I do use virtual hosts to host many different sites that run UAP. Just never the same install. I am guessing if it does not work by default, that it would be in the cookie settings to do so. Let me take a look and see if I see anything.

davarravad commented 7 years ago

Looking at the cookie file, maybe if you remove the domain var from it. I will give it a try and let you know if it still works.

https://github.com/UserApplePie/UserApplePie-v4/blob/master/app/System/Libraries/Auth/Cookie.php

davarravad commented 7 years ago

I tested this code on the demo site and it still worked. All I did was removed the domain vars. Try and out and let me know if it works. If not we will come up with a solution together.

Cookie.php location: app/System/Libraries/Auth/Cookie.php

<?php
/**
 * Auth Cookie Class
 *
 * UserApplePie
 * @author David (DaVaR) Sargent <davar@userapplepie.com>
 * @version 4.0.0
 *
 * @author Jhobanny Morillo <geomorillo@yahoo.com>
 */

namespace Libs\Auth;

class Cookie {

    public static function exists($key) {
        if (isset($_COOKIE[$key])) {
            return true;
        } else {
            return false;
        }
    }

    public static function set($key, $value, $expiry = "", $path = "/") {
        $retval = false;
        if (!headers_sent()) {

            $retval = @setcookie($key, $value, $expiry, $path);
            if ($retval)
                $_COOKIE[$key] = $value;
        }
        return $retval;
    }

    public static function get($key, $default = '') {
        return (isset($_COOKIE[$key]) ? $_COOKIE[$key] : $default);
    }

    public static function display() {
        return $_COOKIE;
    }

    public static function destroy($key, $value = '', $path = "/") {
        if (isset($_COOKIE[$key])) {
            unset($_COOKIE[$key]);
            setcookie($key, $value, time() - 3600, $path);
        }
    }

}
sollidius commented 7 years ago

hmmm. I tried changing the file like this. But after I login, it says "Success! You Have Successfully Logged In!". But apparently it logs me out automatically, because the user dropdown isn't shown and it asks for the login again. This happens on both domains now.

But another solution I'm open to is: copying over all files so /var/www/UAP1 and /var/www/UAP2 And let them connect to the same database. That should be possible right? Can i install UAP2 and just follow the instructions from the auto installer, or would that wipe the existing database?

sollidius commented 7 years ago

Installed it in 2 subfolders now. Had to install modcloudflare to get the real IP address cause it was conflicting. Now I can login on both sites with the same username/password. However, when I log in to SITE1 it auto logs me out of SITE2.

Would there be an easy fix, like where i copy over the session table. So SITE1 uses uap4_session and SITE2 uses uap4_session2 and SITE3 uses uap4_session3 etc and then edit the auth script to check in the correct table? so they share the whole database, except the session table. Or would that still have issues when validating ?

sollidius commented 7 years ago

Okay so I tried doing this. went into the second folder and changed all "PREFIX"sessions to "PREFIX"sessions2 and edited app/system/libraries/auth addIntoDB("sessions2...) as well. I can confirm, it works to be logged in on both sites simultaneously. You do need to login twice (1x per site), but the rest works without issues :) Knowing this, I can continue implementing my current tools into UAP. PS: good job. I really like it. Just need to figure a bit out how the homepage content stuff works, since I never actually use Libraries from others and use plain PHP code. Also nice dashboard stats, you're not the only one who likes those ;) However, it multiplies them by 5 by default (cause of .css and .js etc). So perhaps add a setting to let the dashboard show the logs amount devided by X or make something so .css and .js files aren't counted in the pageviews?

davarravad commented 7 years ago

Thanks I will look in to the stats. I will have more time to work on it soon.

I need to get the docs done. I keep putting it off. Lol