Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Detecting Default Admin

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

Page: 1
Go to End
Author Topic: 1194 Views
  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Detecting Default Admin Link to this post

    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

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Detecting Default Admin Link to this post

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

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Detecting Default Admin Link to this post

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

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Detecting Default Admin Link to this post

    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

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Detecting Default Admin Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Detecting Default Admin Link to this post

    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?

    1194 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.