Seite 1 von 1
Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Di 13. Mai 2014, 11:55
von McHubi
Hallo zusammen,
ich habe mich einmal auf die Suche gemacht nach einem Modul, mit dem ein FE-User das ihm zugeteilte Passwort selbst ändern kann. Gefunden habe ich das hier im Bereich der 4.8er:
http://forum.contenido.org/viewtopic.php?f=61&t=24962
Bringt mich jedoch nicht weiter, da
nicht mehr möglich ist.
Folgende Dateien haben mich nicht weitergebracht:
contenido\includes\include.frontend.user_edit.php
-> hieraus könnte ich ja den Part
Code: Alles auswählen
if ($newpd != $newpd2) {
$messages[] = i18n("Could not set new password: Passwords don't match");
} else {
if ($newpd != "") {
$feuser->set("password", $newpd);
}
}
brauchen - allerdings weiß ich nicht, wo die Variable $newpd mit Inhalt gefüllt wird. Hier muss es also noch eine andere Datei geben, die diese Daten an die include.frontend.user_edit.php "weiterreicht".
Das führt mich zur Datei "contenido\classes\contenido\class.frontend.user.php" und diesen Abschnitt:
Code: Alles auswählen
public function setField($field, $value, $safe = true) {
if ($field == 'password') {
return parent::setField($field, hash('sha256', md5($value) . $this->get('salt')), $safe);
} else {
return parent::setField($field, $value, $safe);
}
}
Gibt es schon für die 4.9er ein Modul, mit dem ein FE-User sein Passwort nach dem Einloggen selbst ändern kann?
Wenn nein, wäre ich sehr dankbar für Tipps!
VG,
Markus
Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Di 13. Mai 2014, 13:47
von Oldperl
Hallo Markus,
schau Dir mal die Klassen cApiFrontendUserCollection und cApiFrontendUser in contenido/classes/contenido/class.frontend.user.php an. Die "alten" Klassen wurden eigentlich nur umbenannt bzw. für die neue cApi migriert.
Edit: Achja, das PW kommt aus der Datei contenido/includes/include.frontend.user_edit.php (Zeile 107 ff)
Gruß aus Franken
Ortwin
Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Di 13. Mai 2014, 14:48
von McHubi
Hallo Ortwin,
Danke Dir für Deine Antwort. Habe mich inzwischen "durchgeboxt" und es zum Laufen bekommen. Der Output für die 4.9 muss so aussehen:
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - Output
*
* Modulname : Change Password 1.1
* Author : HerrB
* Copyright :
* Created : 17.11.2005
* Modified : 22-02-2007 (schlaucher) / 2014-05-13 (Markus Hübner, -> Contenido 4.9.3)
************************************************/
$frontendusers = new cApiFrontendUserCollection;
$frontendusers->select("idclient = '$client' AND username = '".urlencode($auth->auth[uname])."'");
if ($frontenduser = $frontendusers->next()) {
$idfrontend = $frontenduser->get("idfrontenduser");
$pwdmin = "CMS_VALUE[1]";
$pwdmax = "CMS_VALUE[2]";
$pwdsmall = "CMS_VALUE[3]";
$pwdbig = "CMS_VALUE[4]";
$pwdnum = "CMS_VALUE[5]";
$pwdspecial = "CMS_VALUE[6]";
$strMsg = "";
if ($_REQUEST["action"] == "save") {
if ($_REQUEST["oldpw"] != "" || $_REQUEST["newpw1"] != "" || $_REQUEST["newpw2"] != "") {
if ($_REQUEST["oldpw"] == "") {
$strMsg = mi18n("If changing the password please provide the current password.");
} else if ($_REQUEST["newpw1"] == "" || $_REQUEST["newpw2"] == "") {
$strMsg = mi18n("If changing the password please specify new password and retype the new password to avoid typos.");
} else if (hash('sha256', md5($_REQUEST["oldpw"]).$oFeUser->get('salt')) != $frontenduser->get("password")) {
$strMsg = mi18n("Old password is wrong.");
} else if ($_REQUEST["newpw1"] != $_REQUEST["newpw2"]) {
$strMsg = mi18n("If changing the password the new password and the retyped new password must be equal.");
} else if (strlen($_REQUEST["newpw1"]) > $pwdmax ) {
$strMsg = mi18n("If changing the password please specify a new password with 24 characters max..");
} else if (strlen($_REQUEST["newpw1"]) < $pwdmin ) {
$strMsg = mi18n("If changing the password please specify a new password with at least 6 characters.");
} else if ($_REQUEST["newpw1"] == $_REQUEST["oldpw"]) {
$strMsg = mi18n("If changing the password the old password and the new password must be different.");
} else if ($_REQUEST["newpw1"] == urlencode($auth->auth[uname])) {
$strMsg = mi18n("If changing the password the username and the new password must be different.");
} else if ($pwdsmall == 'yes' && !ereg ("[a-z]", $_REQUEST["newpw1"])) {
$strMsg = mi18n("Password must contain small characters.");
} else if ($pwdbig == 'yes' && !ereg ("[A-Z]", $_REQUEST["newpw1"])) {
$strMsg = mi18n("Password must contain big characters.");
} else if ($pwdnum == 'yes' && !ereg ("[0-9]", $_REQUEST["newpw1"])) {
$strMsg = mi18n("Password must contain numbers.");
} else if ($pwdspecial == 'yes' && ereg ("^[a-zA-Z0-9]+$",$_REQUEST["newpw1"])) {
$strMsg = mi18n("Password must contain special characters.");
}
}
if ($strMsg == "" && $_REQUEST["oldpw"] != "") {
$frontenduser->set("password", $_REQUEST["newpw1"]);
$frontenduser->store();
$strMsg = mi18n("Changes has been saved.");
} else {
$strMsg = '<font color="#FF0000">'.$strMsg.'</font>';
}
}
echo '<div id="form">';
echo '<form name="frmProfile" method="post" action="front_content.php?idart='.$idart.'">',chr(10);
//echo '<form name="frmProfile" method="post" action="'.$auth->url().'">',chr(10);
echo ' <table class="special" cellspacing="0"> ',chr(10);
echo ' <tr>',chr(10);
echo ' <td class="detail_headline" colspan="2"><h2>'.mi18n("Change Password:").'</h2></td>',chr(10);
echo ' </tr>',chr(10);
if ($strMsg != "") {
echo ' <tr>',chr(10);
echo ' <td class="detail_text" colspan="2">'.$strMsg.'</td>',chr(10);
echo ' </tr>',chr(10);
}
echo ' <tr>',chr(10);
echo ' <tr>',chr(10);
echo ' <td class="detail_text" style="width: 150px;">'.mi18n("Old password:").'</td>',chr(10);
echo ' <td class="detail_text"><input class="input" name="oldpw" type="password" size="24" maxlength="24"></td>',chr(10);
echo ' </tr>',chr(10);
echo ' <tr>',chr(10);
echo ' <td class="detail_text" style="width: 150px;">'.mi18n("New password:").'</td>',chr(10);
echo ' <td class="detail_text"><input class="input" name="newpw1" type="password" size="24" maxlength="24"></td>',chr(10);
echo ' </tr>',chr(10);
echo ' <tr>',chr(10);
echo ' <td class="detail_text" style="width: 150px;">'.mi18n("Retype password:").'</td>',chr(10);
echo ' <td class="detail_text"><input class="input" name="newpw2" type="password" size="24" maxlength="24"></td>',chr(10);
echo ' </tr>',chr(10);
echo ' <tr>',chr(10);
echo ' <td class="detail_text" colspan="2"> </td>',chr(10);
echo ' </tr>',chr(10);
echo ' <tr>',chr(10);
echo ' <td class="detail_text" style="width: 100px;"> </td>',chr(10);
echo ' <td class="detail_text"><input type="hidden" name="action" value="save"><input class="button" name="subscribe" type="submit" id="subscribe" value="'.mi18n("OK").'"></td>',chr(10);
echo ' </tr>',chr(10);
echo ' </table>',chr(10);
echo '</form></div>',chr(10);
}
?>
Angepasst habe ich diese Abschnitte:
Code: Alles auswählen
cInclude("classes", "class.frontend.users.php");
$frontendusers = new FrontendUserCollection;
->
und
Code: Alles auswählen
} else if (md5($_REQUEST["oldpw"]) != $frontenduser->get("password")) {
->
Code: Alles auswählen
} else if (hash('sha256', md5($_REQUEST["oldpw"]).$oFeUser->get('salt')) != $frontenduser->get("password")) {
Sollte also jetzt passen, Feinschliff in punkto HTML-Templates usw. muss natürlich noch...

Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Mi 14. Mai 2014, 13:51
von McHubi
Hallo zusammen,
habe das Modul überarbeitet, entschlackt und auf die 4.9er angepasst. Hinzu kommt, dass die Fehlerhinweise jetzt nicht mehr einzeln eingeblendet werden sondern als Liste. Die Einzeleinblendung nervte...
INPUT
Code: Alles auswählen
/***********************************************
* CONTENIDO MODUL - INPUT
*
* Modulname : Change Password 1.1
* Author : HerrB
* Copyright :
* Created : 17.11.2005
* Modified : 22-02-2007 (schlaucher) / 2014-05-13 (Markus Hübner, -> Contenido 4.9.3)
************************************************/
if ("CMS_VALUE[1]" == '') $pwdmin = 6;
else $pwdmin = "CMS_VALUE[1]";
if ("CMS_VALUE[2]" == '') $pwdmax = 20;
else $pwdmax = "CMS_VALUE[2]";
if ("CMS_VALUE[3]" == '') $pwdsmall = '';
else $pwdsmall = ' checked';
if ("CMS_VALUE[4]" == '') $pwdbig = '';
else $pwdbig = ' checked';
if ("CMS_VALUE[5]" == '') $pwdnum = '';
else $pwdnum = ' checked';
if ("CMS_VALUE[6]" == '') $pwdspecial = '';
else $pwdspecial = ' checked';
echo '
<table cellspacing="0" border="0">
<tr>
<td>'.mi18n("Password length:").'</td>
<td>'.mi18n("min. size:").'</td>
<td><input type="text" name="CMS_VAR[1]" value="'.$pwdmin.'" size="5" /></td>
</tr>
<tr>
<td></td>
<td>'.mi18n("max. size").'</td>
<td><input type="text" name="CMS_VAR[2]" value="'.$pwdmax.'" size="5" /></td></tr>
<tr>
<td>'.mi18n("Password has to contain:").'</td>
<td>'.mi18n("small characters").'</td>
<td><input type="checkbox" name="CMS_VAR[3]" value="yes" '.$pwdsmall.' /></td>
</tr>
<tr>
<td></td>
<td>'.mi18n("big characters").'</td>
<td><input type="checkbox" name="CMS_VAR[4]" value="yes" '.$pwdbig.' /></td>
</tr>
<tr>
<td></td>
<td>'.mi18n("numbers").'</td>
<td><input type="checkbox" name="CMS_VAR[5]" value="yes" '.$pwdnum.' /></td></tr>
<tr>
<td></td>
<td>'.mi18n("special characters").'</td>
<td><input type="checkbox" name="CMS_VAR[6]" value="yes" '.$pwdspecial.' /></td>
</tr>
</table>';
OUTPUT
Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - Output
*
* Modulname : Change Password 1.1
* Author : HerrB
* Copyright :
* Created : 17.11.2005
* Modified : 22-02-2007 (schlaucher) / 2014-05-13 (Markus Hübner, -> Contenido 4.9.3)
************************************************/
// assert framework initialization
defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
$frontendusers = new cApiFrontendUserCollection;
$frontendusers->select("idclient = '$client' AND username = '".urlencode($auth->auth[uname])."'");
if($frontenduser = $frontendusers->next()) {
$idfrontend = $frontenduser->get("idfrontenduser");
$pwdmin = "CMS_VALUE[1]";
$pwdmax = "CMS_VALUE[2]";
$pwdsmall = "CMS_VALUE[3]";
$pwdbig = "CMS_VALUE[4]";
$pwdnum = "CMS_VALUE[5]";
$pwdspecial = "CMS_VALUE[6]";
$arrMsg = array();
if($_REQUEST["action"] == "save")
{
if($_REQUEST["oldpw"] != "" || $_REQUEST["newpw1"] != "" || $_REQUEST["newpw2"] != "")
{
if($_REQUEST["oldpw"] == "") $arrMsg[] = mi18n("If changing the password please provide the current password.");
if($_REQUEST["newpw1"] == "" || $_REQUEST["newpw2"] == "") $arrMsg[] = mi18n("If changing the password please specify new password and retype the new password to avoid typos.");
if(hash('sha256', md5($_REQUEST["oldpw"]).$oFeUser->get('salt')) != $frontenduser->get("password")) $arrMsg[] = mi18n("Old password is wrong.");
if($_REQUEST["newpw1"] != $_REQUEST["newpw2"]) $arrMsg[] = mi18n("If changing the password the new password and the retyped new password must be equal.");
if(strlen($_REQUEST["newpw1"]) > $pwdmax ) $arrMsg[] = mi18n("If changing the password please specify a new password with 24 characters max..");
if(strlen($_REQUEST["newpw1"]) < $pwdmin ) $arrMsg[] = mi18n("If changing the password please specify a new password with at least 6 characters.");
if($_REQUEST["newpw1"] == $_REQUEST["oldpw"]) $arrMsg[] = mi18n("If changing the password the old password and the new password must be different.");
if($_REQUEST["newpw1"] == urlencode($auth->auth[uname])) $arrMsg[] = mi18n("If changing the password the username and the new password must be different.");
if($pwdsmall == 'yes' && !ereg ("[a-z]", $_REQUEST["newpw1"])) $arrMsg[] = mi18n("Password must contain small characters.");
if($pwdbig == 'yes' && !ereg ("[A-Z]", $_REQUEST["newpw1"])) $arrMsg[] = mi18n("Password must contain big characters.");
if($pwdnum == 'yes' && !ereg ("[0-9]", $_REQUEST["newpw1"])) $arrMsg[] = mi18n("Password must contain numbers.");
if($pwdspecial == 'yes' && ereg ("^[a-zA-Z0-9]+$",$_REQUEST["newpw1"])) $arrMsg[] = mi18n("Password must contain special characters.");
}
if(empty($arrMsg) && $_REQUEST["oldpw"] != "")
{
$frontenduser->set("password", $_REQUEST["newpw1"]);
$frontenduser->store();
echo mi18n("Changes has been saved.");
}
else
{
echo mi18n("Please regard following information:").'<ul>';
foreach($arrMsg AS $element) echo '<li>'.$element.'</li>';
echo '</ul>';
}
}
// When in backend edit mode add a label
if (cRegistry::isBackendEditMode()) $label = mi18n("LABEL_TEXT");
else $label = NULL;
// use smarty template to display form
$tpl = cSmartyFrontend::getInstance();
$tpl->assign('label', $label);
$tpl->assign('idart', $idart);
$tpl->assign('change_password', mi18n("Change Password:"));
$tpl->assign('old_password', mi18n("Old password:"));
$tpl->assign('new_password', mi18n("New password:"));
$tpl->assign('retype_password', mi18n("Retype password:"));
$tpl->display('form.tpl');
}
?>
HTML
(als "form.tpl" im entsprechenden Reiter "HTML" des Moduls anlegen)
Code: Alles auswählen
{if 0 lt $label|strlen}
<label class="content_type_label">{$label}</label>
{/if}
<form name="frmProfile" method="post" action="front_content.php?idart={$idart}">
<table>
<tr>
<td colspan="2"><h2>{$change_password}</h2></td>
</tr>
<tr>
<td>{$old_password}</td>
<td><input name="oldpw" type="password" size="24" maxlength="24"></td>
</tr>
<tr>
<td>{$new_password}</td>
<td><input name="newpw1" type="password" size="24" maxlength="24"></td>
</tr>
<tr>
<td>{$retype_password}</td>
<td><input name="newpw2" type="password" size="24" maxlength="24"></td>
</tr>
<tr>
<td></td>
<td><input type="hidden" name="action" value="save"><input name="subscribe" type="submit" id="subscribe" value="OK"></td>
</tr>
</table>
</form>
CSS-Spielereien hab ich mir verkniffen, das wird wohl jeder selbst in die Hand nehmen wollen...
VG,
Markus
Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Mi 14. Mai 2014, 13:57
von Faar
Danke

Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Mi 14. Mai 2014, 14:15
von Oldperl
McHubi hat geschrieben:habe das Modul überarbeitet, entschlackt und auf die 4.9er angepasst.
Fein gemacht Markus.
Bis auf die unnötige Verwendung von Smarty.

Hier hätte cTemplate locker gereicht.
Gruß aus Franken
Ortwin
Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Mi 14. Mai 2014, 14:52
von Faar
Smartyitis ist ansteckend

Re: Passwort für Frontenduser - Änderung durch Frontenduser
Verfasst: Mi 14. Mai 2014, 15:40
von McHubi
Bis auf die unnötige Verwendung von Smarty.

Hier hätte cTemplate locker gereicht.
Jaaaaa... Ist schon richtig. Bei dem simplen Ding hätte man das Ganze natürlich auch einfach direkt alles im Modul-Output regeln können. Aber:
Smartyitis ist ansteckend

