Re: User class(es)

From: Date: Fri, 27 Apr 2001 01:09:12 +0000
Subject: Re: User class(es)
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-329@lists.php.net to get a copy of this message
At 06:46 2001-04-26 +0000, you wrote:
For a portal project I'm working on I'm going to be developing a triad of user management classes. The first class will be an admin class and will have methods such as add/delete user, reset password, grant/revoke user permissions, and activate/deactivate user. The second class will be a user manager class and a factory for the third class. This class will have methods such as set email address, set real name, set prefrences, and other "user" type data. It will also have an auth method. The auth method will authenticate and upon sucess, will return an instance of the third class (as well as set an internal variable that will be required for any of the other functions to work). The third class will be a small class with simple methods like get real name, check prefrences, check permissions, list prefrences, get email address, etc... the point of this class will be that it could be registered with session_register() and kept persistent throughout the session. The practicle upshot is that the user information is available in a easy, intuative way. For an example, let's say I support two displays for my portal, with icons and without (as in Slashdot). With this class I could simply if (s_user->checkPrefs("icon")) {
        ... show the icon ...
} Once I have this done, I'll submit it for discussion. Does anybody have any thoughts/critisisms (other than my spelling :-)) about this idea/architecture?
Some thoughts... I've done a user management system for a websystem (www.ostgota.lu.se). I used serialized objects in sessionsdata. In prepend.php: <code>
        include(APPLICATION_PATH.'session.class.php');
        session_start();
        session_register('SESSION');
        if (empty($SESSION)) {
                $SESSION = &new OG_Session;
        } else {
                $SESSION->updateVisit();
        }
</code> The OG_Session-object (subclassing Session) contains info about the connection and session such as client's browser, ip, stylsheet to use, number of pages visited, logging and so on. These values are generic for all sites. Methods for things such as updating number of visits are also provided. It also contains a OG_User-object, which is unique for every system. In my case it contains the user's name, number, clearance and so on. This object also contains methods for authorizing pages. In this way I can do things like <php>
        <?= ($SESSION->user->auth('adminNews.php')) ? '<a href="/adminNews.php?newsId='.$news[$i]->newsId().'">change newsitem</a>' : '' ?>
</php> or <code>
        if ($SESSION->user->authThisPage()) {
                stuff to do if user is allowed on the current page...
        }
</code> Simpler stuff: <php>
        Logged in as: <?= $SESSION->user->userName() ?>
</php> And when a user log off: <code>
        $SESSION->user = &new OG_User;
</code> Log on... <code>
        $SESSION->user->logOn($person->personName(), $person->personStatus() ..... );
</code> /erik hjortsberg

« previous php.pear.dev (#329) next »