1 User liest/lesen diesen Beitrag: (0 Mitglieder, und 1 Gast).

Antwort schreiben 
 
Themabewertung:
  • 0 Bewertungen - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Das Frontend-Login in den Templates ...
11.08.2008, 17:27
Beitrag: #1
Das Frontend-Login in den Templates ...
... ist schon ein harter Brocken:
PHP-Code:
<?
        if(FRONTEND_LOGIN == 'enabled' AND VISIBILITY != 'private' AND $wb->get_session('USER_ID') == '') {
        ?>
        <form action="<?php echo LOGIN_URL?>" method="post" class="login_table">
            <p><?php echo $TEXT['LOGIN']; ?></p>
            <?php echo $TEXT['USERNAME']; ?>:
            <input type="text" name="username" style="text-transform: lowercase;" />
            <?php echo $TEXT['PASSWORD']; ?>:
            <input type="password" name="password" />
            <input type="submit" name="submit" value="<?php echo $TEXT['LOGIN']; ?>" style="margin-top: 3px; text-transform: uppercase;" />
            <a href="<?php echo FORGOT_URL?>"><?php echo $TEXT['FORGOT_DETAILS']; ?></a>
                <?php if(is_numeric(FRONTEND_SIGNUP)) { ?>
                    <a href="<?php echo SIGNUP_URL?>"><?php echo $TEXT['SIGNUP']; ?></a>
                <?php ?>
        </form>
        <?php
        
} elseif(FRONTEND_LOGIN == 'enabled' AND is_numeric($wb->get_session('USER_ID'))) {
        
?>
        <form action="<?php echo LOGOUT_URL?>" method="post" class="login_table">
            <p><?php echo $TEXT['LOGGED_IN']; ?></p>
            <p><?php echo $TEXT['WELCOME_BACK']; ?><?php echo $wb->get_display_name(); ?></p>
            <p>
            <input type="submit" name="submit" value="<?php echo $MENU['LOGOUT']; ?>" />
            <br />
            <a href="<?php echo PREFERENCES_URL?>"><?php echo $MENU['PREFERENCES']; ?></a>
            <a href="<?php echo ADMIN_URL?>/index.php"><?php echo $TEXT['ADMINISTRATION']; ?></a></p>
        </form>
        <?php
        
}
        
?>

Und - ich gestehe - eine richtig gute Lösung habe ich noch nicht, ausser:
PHP-Code:
<?
/**
*    function for a mini-template-sytem
*/
function replace_all ($aStr = "", &$aArray ) {
    foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
    return $aStr;
}

/**
*    Frontend Login
*/
if ( 
     ( FRONTEND_LOGIN == 'enabled')    AND 
     ( VISIBILITY != 'private')        AND 
     ( $wb->get_session('USER_ID') == '') ) {

    $form_template  = "<form name='login' action='{{action}}' method='post'>\n";
    $form_template .= "<p>{{login_text}}</p>\n";
    $form_template .= "{{user_name}}: <input type='text' name='username'><br>\n";
    $form_template .= "{{password}} : <input type='password' name='password'><br>\n";
    $form_template .= "<input type='submit' value='{{submit}}'>\n";
    $form_template .= "{{signup}}\n";
    $form_template .= "</form>";

    $form_values = array (
        'action'    => "login.php",
        'login_text'=> $TEXT['LOGIN'],
        'password'    => $TEXT['PASSWORD'],
        'submit'    => $TEXT['LOGIN'],
        'signup'    => is_numeric(FRONTEND_SIGNUP) ? "<a href=\"".SIGNUP_URL."\">".$TEXT['SIGNUP']."</a>" : ""
    );

    $login_form = replace_all ($form_template, $form_values);

    echo "<div id=\"login_box\">\n".$login_form."</div>\n";
    
} elseif (
    ( FRONTEND_LOGIN=='enabled' )    AND 
    ( is_numeric($wb->get_session('USER_ID'))) ) {

    $form_template  = "<form name='login' action='{{action}}' method='post'>\n";
    $form_template .= "{{login_text}}\n";
    $form_template .= "<input type='submit' value='{{submit}}'>\n";
    $form_template .= "{{signup}}<br>\n";
    $form_template .= "{{pref}}\n{{admin}}<br>\n";
    $form_template .= "</form>";

    $form_values = array (
        'action'    => "logout.php",
        'login_text'=> $TEXT['LOGGED_IN']."<br>".$TEXT['WELCOME_BACK'].$wb->get_display_name(),
        'submit'    => $TEXT['LOGOUT'],
        'signup'    => is_numeric(FRONTEND_SIGNUP) ? "<a href=\"".SIGNUP_URL."\">".$TEXT['SIGNUP']."</a>" : "",
        'pref_add'    => "<a href=\"".PREFERENCES_URL."\>".$MENU['PREFERENCES']."</a>",
        'admin'        => "<a href=\"".ADMIN_URL."/index.php\">".$TEXT['ADMINISTRATION']."</a>\n"  
    );

    $login_form = replace_all ($form_template, $form_values);
    
    echo "<div id=\"login_box\">\n".$login_form."</div>\n";
}
?>

Ja - ich weiss: mal wieder Templates ...

to be continued ...

Gruß
Aldus

[Bild: aldus_01.gif]
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
14.08.2008, 12:29 (Dieser Beitrag wurde zuletzt bearbeitet: 14.08.2008 13:36 von aldus.)
Beitrag: #2
Das Frontend-Login in den Templates ... PEAR?
Nun - dann schreibe ich halt meinen eigenen Kommentar ...

Ein Ausweg könnte, z.Zt grob skizziert, so aussehen:
PHP-Code:
<?php
/**
*    PEAR Login
*
*    @version    0.2.0
*    @build        3
*    @date        2008-08-14
*    @author        aldus
*    @package    Websitebaker - Code Examples
*    @state        @dev
*
*/

require_once ("HTML/QuickForm.php");

/**
*    Form-templates
*/

$form_temp "<form {attributes}>{content}</form>";

$element_temp  "<div class='login_required'><!-- BEGIN required -->* <!-- END required --></div>";
$element_temp .= "<div class='login_label'>{label}</div>";
$element_temp .= "<div class='login_element'>{element}</div>";
$element_temp .= "<div class='login_error'><!-- BEGIN error -->{error}<!-- END error --></div>";

/**
*    Styles
*/
$style "class='login_text'";

$form = new HTML_QuickForm("login""post"$_SERVER['PHP-SELF'], """class='login_form'" );

$renderer $form->defaultRenderer();
$renderer->setFormTemplate($form_temp);
$renderer->setElementTemplate($element_temp);

$form->addElement("text",     "username",    "Name"$style);
$form->addElement("password",    "pass",        "Pass"$style);
$form->addElement("submit",    "submit",    $TEXT['SIGNUP'], $style);

$form->accept($renderer);

echo 
$renderer->toHTML();

?>

An sich schon ganz nett, wenn auch noch nicht ausgereift und WB tauglich.

So - und formatieren kann man es dann im CSS vieleicht so:
Code:
form.login_form {
    margin-top:20px;
}
div.login_label {
    display:block;
    width: 60px;
    font-family: Verdana, sans-serif;
    color:#900;
    float:left;
    text-align:right;
    padding-right:10px;
}
div.login_element {
    display.block;
    height: 24px;
    margin-bottom:3px;
}
input.login_text {
    display:block;
    width: 150px;
    font-family: Verdana, sans-serif;
    font-size:11px;
}
input[type='submit'] {
    display:block;
    width:150px;
    margin-left:70px;
    margin-top:10px;
}

To be contiued ...

Gruß
Aldus

[Bild: aldus_01.gif]
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
14.08.2008, 15:41 (Dieser Beitrag wurde zuletzt bearbeitet: 14.08.2008 15:45 von aldus.)
Beitrag: #3
RE: Das Frontend-Login in den Templates ...
Gut, Version 0.3.0 mit Anpassungen für Websitebaker:

PHP-Code:
<?php
/**
*    PEAR Login
*
*    @version    0.3.0
*    @build        4
*    @date        2008-08-14
*    @author        aldus
*    @package    Websitebaker - Code Examples
*    @state        @dev
*
*/

require_once ("HTML/QuickForm.php");

/**
*    Form-templates
*/

$form_temp "<div id='loginmaske'><form {attributes}>{content}</form></div>";

$element_temp  "<div class='login_required'><!-- BEGIN required -->* <!-- END required --></div>";
$element_temp .= "<div class='login_label'>{label}</div>";
$element_temp .= "<div class='login_element'>{element}</div>";
$element_temp .= "<div class='login_error'><!-- BEGIN error -->{error}<!-- END error --></div>";

/**
*    Styles
*/
$style "class='login_text'";


if (     
FRONTEND_LOGIN == 'enabled' AND 
    
VISIBILITY != 'private' AND 
    
$wb->get_session('USER_ID') == '') {
        
    
$form = new HTML_QuickForm("login""post"LOGIN_URL """class='login_form'" );

    
$renderer $form->defaultRenderer();
    
$renderer->setFormTemplate($form_temp);
    
$renderer->setElementTemplate($element_temp);

    
$form->addElement("html",    "<p>".$TEXT['LOGIN']."</p>");
    
$form->addElement("text",    "username",    $TEXT["USERNAME"], $style);
    
$form->addElement("password",    "pass",        $TEXT['PASSWORD'], $style);
    
$form->addElement("submit",    "submit",    $TEXT['LOGIN'], $style);
    
$form->addElement("html",    "<a href='".FORGOT_URL."'>".$TEXT['FORGOT_DETAILS']."</a>");
    
    if ( 
is_numeric(FRONTEND_SIGNUP) ) $form->addElement("html""<a href='".SIGNUP_URL."'>".$TEXT['SIGNUP']."</a>");
    
    
$form->accept($renderer);

    echo 
$renderer->toHTML();

} elseif ( 
    
FRONTEND_LOGIN=='enabled' AND 
    
is_numeric($wb->get_session('USER_ID'))) {
    
    
$form = new HTML_QuickForm("logout""post"LOGOUT_URL """class='login_form'" );
    
    
$renderer $form->defaultRenderer();
    
$renderer->setFormTemplate($form_temp);
    
$renderer->setElementTemplate($element_temp);
    
    
$form->addElement("html",    "<p>".$TEXT['LOGGED_IN']."</p>");
    
$form->addElement("html",    "<p>".$TEXT['WELCOME_BACK'].",".$wb->get_display_name()."</p>");
    
$form->addElement("submit",    "submit",    $MENU['LOGOUT'], $style);
    
$form->addElement("html",    "<a href='".PREFERENCES_URL."'>".$MENU['PREFERENCES']."</a>");
    
$form->addElement("html",    "<a href='".ADMIN_URL."'>".$TEXT['ADMINISTRATION']."</a>");
    
    
$form->accept($renderer);

    echo 
$renderer->toHTML();
}
?>

Ein wenig ärglich sind hier halt die doppelten Codeblöcke in den beiden Bedingugen. M.f.i.

Gruß
Aldus

[Bild: aldus_01.gif]
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Gehe zu:


Kontakt | Websitebaker Hilfe | Nach oben | Zum Inhalt | Archiv-Modus | RSS-Synchronisation