Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Detecting Default Admin


Reply


6 Posts   1271 Views

Avatar
swaiba

Forum Moderator, 1805 Posts

20 September 2010 at 9:48pm

Hi,

I can detect the user with Member::currentUser(), I wonder is there a way of detecting if the user that is returned is actually logged in or if it is the default admin that has been set in the _config (Security::setDefaultAdmin('Admin', 'Admin')) instead?

Barry

Avatar
baba-papa

Community Member, 279 Posts

22 September 2010 at 5:06pm

Admins are usualy in their own group. You can check that with inGroup() of the class Member.

Avatar
Willr

Forum Moderator, 5513 Posts

22 September 2010 at 6:32pm

Or use Permission::check('ADMIN'); to check for any admin rights on the current member.

Avatar
swaiba

Forum Moderator, 1805 Posts

22 September 2010 at 8:18pm

Hi guys,

thanks for the answers although they have both slightly missed the mark... I'll explain a little more... if I have the following in _config.php...

Security::setDefaultAdmin('Admin', 'Admin');

and within "Security -> Security Groups -> Administrators" the user...

Swaiba - Swaiba - swaiba@swaiba.com - Swaiba

Either way if I login with Admin / Admin or Swaiba / Swaiba I will return true to being an administrator and the member DataObject returned will be the same.

What I am asking is can I tell that one user logged in the with the user/pass from the secrutiy system (Swaiba / Swaiba) or whether they have logged in using the default admin stuff (Admin / Admin)

Barry

Avatar
baba-papa

Community Member, 279 Posts

22 September 2010 at 8:40pm

I´m not the most experienced SS developer, but afaik the default admin is a admin like any other admin. With a dev/build the default admin gets his entry in the databases member table. Like this you can´t tell the default admin directly from an admin registered via the backend. There is one little differnce: A default admin has no Surname/Name. Maybe you can validate if those attributes are set or not.
Cheers

Avatar
swaiba

Forum Moderator, 1805 Posts

22 September 2010 at 10:28pm

No worries, I'd prefer not to rely on the name being 'Default Admin' and there being no surname as if this user is not there the defaultAdmin in _config will use an existing user.

Any other ideas? willr?