The first user

From ISPWiki
Jump to: navigation, search

COREmanager allows to log in to the system with login and password of the server administrator. However, many functions can be performed only with permissions of the administrator created in the control panel.

Let's consider that you already have a list of administrators:

class AdminManagement : public ExtListAction {
public:
  AdminManagement(): ExtListAction<UserTable>("admin", MinLevel(lvAdmin)) {}
  ...
};

Add one more Action into this class:

class AdminManagement : public ExtListAction {
public:
  AdminManagement(): ExtListAction<UserTable>("admin", MinLevel(lvAdmin)), login(this) {}
  ...
  class Login : public Action {
  public:
    Login(Action *parent) : Action("login", MinLevel(lvSuper), parent) {}
    virtual void Execute(Session &ses) const {
      // call a function that will return the name of the first administrator 
      string user = GetAnyAdmin();
      if (user.empty()) {
        // if there are no administrators in your system, create a new one 
        InternalCall(ses, parent()->name() + ".edit", "sok=ok&name=admin&passwd=" + str::hex::Encode(str::Random(15));
        user = "admin";
      }
      // call the standard function of COREmanager to drill down to the selected user  
      ses.xml = InternalCall(ses, "su", "elid=" + str::url::Encode(user));
    }
  } login;
};

Add a button on the Dashboard toolbar of the superuser to drill down to the administrator level.

  ...
  <block name="taskbar" position="top" type="toolbar">
    <toolbtn top="admin.login" img="mb-provider" name="admin"/>
    ...
  </block>
  ...