API for user account plugins

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

API for user account plugins

Post by cmb » Mon Dec 08, 2014 2:11 pm

Hello Community,

I propose to define an API for user account plugins, such as Memberpages and Register_XH (and others which may be developed in the future). There are already some plugins which (are able to) work in combination with the mentioned plugins, for instance, Forum_XH and Schedule_XH. Currently this is done by accessing the username that is stored in the session; however, I consider this to be a very brittle solution, because it ties to an implementation detail (the name of the session variable might change, and the user name might not even be stored in the session at all). I had presented a quick idea for Register_XH a while ago, but this is probably too closely tied to this very plugin and its way to manage the user permissions. Basically a single function to get the current user name would suffice.

However, there is another issue. Multiple times it has been requested to display the full user name for Forum_XH and Schedule_XH. This might be solved by adding another API which returns the full user name, but this would raise problems when the full user name is changed later, what is easily possible in the control panels of Memberpages and Register_XH. So it seems reasonable to have a single function which returns the current user as an object, which has an immutable ID and offers methods to retrieve the user name resp. the full name. Any plugin which uses the login information of a conforming user account plugin could store the ID when needed, and access the other information for display purposes.

The user objects might implement the following interface:

Code: Select all

interface User
{
    /**
     * Returns the immutable ID of this user.
     *
     * If the username will never change, it may be the username.
     * Otherwise a uniqid() or the value of an autoincrement field could be
     * returned.
     *
     * @return mixed
     */
    public function getId();
    
    /**
     * Returns the username of this user.
     *
     * @return string
     */
    public function getUsername();
    
    /**
     * Returns the full name of this user.
     *
     * @return string
     */
    public function getFullName();
}
While I actually would prefer to have such an interface, it is not clear where to define it. It seems to me that would have to happen in CMSimple_XH's core, what would delay the possible usage of the new API. So for now it might be better to not require the actual interface, but simply rely on a conforming implementation.

Anyhow, there is still the need to retrieve the user object. Two simple functions in $pth['plugin_classes'] would seem to be sufficient:

Code: Select all

function getCurrentUser() {
    // ...
};

function getUserById($id) {
    // ...
}; 
However, it might be better to define these as static class methods to be able to use autoloading.

Any thoughts?

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

manu
Posts: 1090
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: API for user account plugins

Post by manu » Tue Dec 09, 2014 9:05 am

Why not embed these functions/features/methods into a "helper" plugin? IHMO restricted pages is not a core feature of CMSimple_XH. This "helper" plugin could be maintained solely and could be handed out in the Register_XH- or/and Memberpages Plugin zip.files.
How about this?
regards manu

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: API for user account plugins

Post by cmb » Tue Dec 09, 2014 11:12 am

manu wrote:Why not embed these functions/features/methods into a "helper" plugin?
The implementations directly depend on the respective plugin (Memberpages/Register), so they should be part of it. Only the interface(s) (if there'll be any) can't be delivered with the "user account plugin" -- they could be part of a "helper" plugin, though, instead of being included in the core.
manu wrote:IHMO restricted pages is not a core feature of CMSimple_XH.
I agree.
Christoph M. Becker – Plugins for CMSimple_XH

Holger
Site Admin
Posts: 3470
Joined: Mon May 19, 2008 7:10 pm
Location: Hessen, Germany

Re: API for user account plugins

Post by Holger » Fri Dec 12, 2014 12:00 pm

manu wrote:IHMO restricted pages is not a core feature of CMSimple_XH.
Hmm, scheduled pages was not a core feature too ;) .

I think if there is a need of some kind of API, it's better and easier to define and integrate such things in the core.
The question is: do we really need that API?

And BTW, optional features could find their place in optional php-files or subfolders...

Post Reply