Override login form from theme

Discussion in 'Developers' Forum' started by luttje, Mar 11, 2024.

  1. luttje

    luttje New Member

    Hi there,

    First of all: thanks for this great project! I really appreciate it being made available like this.

    On to my question: How can I override the default login form from my theme?
    I can override other templates in other modules by simply placing .htm templates in interface/web/themes/mytheme/templates/modulename/template-to-override.htm
    However since the login page is not a module, ISPConfig doesn't bother to look inside my theme's templates/login directory. The templates I want to customize there are login/index.htm, login/otp.htm and login/password_reset.htm

    Instead it appears (looking at the source-code) that the _fileSearch method in interface/lib/classes/tpl.inc.php:
    1. Passes by the first guard as isset($_SESSION['s']['module']['name']) is false on the login page
    2. Matches the full path, because web/login/index.php looks for $app->tpl->setInclude('content_tpl', 'templates/index.htm'); and finds that relative to the interface/web/ directory

    A naive fix:
    Code:
    // inside _fileSearch in lib/classes/tpl.inc.php
    $modulename = false;
    
    if (isset($_SESSION['s']['module']['name'])) {
      $modulename = $_SESSION['s']['module']['name'];
    } else if ($_SERVER['PHP_SELF'] === '/login/index.php') {
      $modulename = 'login';
    }
    
    if($modulename && isset($_SESSION['s']['theme'])) {
      if(is_file(ISPC_THEMES_PATH.'/'.$_SESSION['s']['theme'].'/templates/'.$modulename.'/'.$filename)) {
        return ISPC_THEMES_PATH.'/'.$_SESSION['s']['theme'].'/templates/'.$modulename.'/'.$filename;
      }
    }
    
    However I haven't enough understanding of the codebase to understand the possible caveats of this approach.

    Would love to hear if I'm missing something.

    Thanks again for your time!
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    I think this should be ok. Changing the template class is normally not a good idea, but I guess it's the best choice for this issue as I'm not sure if setting $_SESSION['s']['module']['name'] generally for login has no other side effects.
     
    luttje likes this.
  3. luttje

    luttje New Member

    Thanks for the swift reply!

    Are you planning on implementing this fix into ISPConfig by any chance? Or is it going to have to be a manual fix?

    If you want me to make a PR on GitLab for this I can help with that (as soon as I get access). I'd test it a bit better as well, to know with more certainty that this doesn't break other pages.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    We should make this a permanent fix. I've just approved your account request at git.ispconfig.org.
     
    ahrasis and luttje like this.
  5. luttje

    luttje New Member

    Thanks for approving my account and merging my merge request so swiftly. Much appreciated.

    For future readers: the above was resolved in git.ispconfig.org/ispconfig/ispconfig3/-/issues/6664
     
    ahrasis likes this.

Share This Page