Passwort für Frontenduser - Änderung durch Frontenduser

Alles rund um Module und Plugins in CONTENIDO 4.9.
Antworten
McHubi
Beiträge: 1223
Registriert: Do 18. Nov 2004, 23:06
Wohnort: Mettmann
Kontaktdaten:

Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag 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

Code: Alles auswählen

cInclude("classes", "class.frontend.users.php");
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! :D

VG,

Markus
seamless-design.de
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.

Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)

Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)
Oldperl
Beiträge: 4316
Registriert: Do 30. Jun 2005, 22:56
Wohnort: Eltmann, Unterfranken, Bayern
Hat sich bedankt: 6 Mal
Danksagung erhalten: 4 Mal
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag 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
ConLite 3.0.0-dev, alternatives und stabiles Update von Contenido 4.8.x unter PHP 8.x - Download und Repo auf Gitport.de
phpBO Search Advanced - das Suchwort-Plugin für CONTENIDO 4.9
Mein Entwickler-Blog
McHubi
Beiträge: 1223
Registriert: Do 18. Nov 2004, 23:06
Wohnort: Mettmann
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag 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">&nbsp;</td>',chr(10);
   echo '    </tr>',chr(10);
   echo '    <tr>',chr(10);
   echo '      <td class="detail_text" style="width: 100px;">&nbsp;</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;
->

Code: Alles auswählen

$frontendusers = new cApiFrontendUserCollection;
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... :wink:
seamless-design.de
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.

Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)

Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)
McHubi
Beiträge: 1223
Registriert: Do 18. Nov 2004, 23:06
Wohnort: Mettmann
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag 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... :wink:
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... :D

VG,

Markus
seamless-design.de
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.

Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)

Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)
Faar
Beiträge: 1951
Registriert: Sa 8. Sep 2007, 16:23
Wohnort: Brandenburg
Hat sich bedankt: 15 Mal
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag von Faar »

Danke :)
Fliegt der Bauer übers Dach, ist der Wind weißgott nicht schwach.
Oldperl
Beiträge: 4316
Registriert: Do 30. Jun 2005, 22:56
Wohnort: Eltmann, Unterfranken, Bayern
Hat sich bedankt: 6 Mal
Danksagung erhalten: 4 Mal
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag von Oldperl »

McHubi hat geschrieben:habe das Modul überarbeitet, entschlackt und auf die 4.9er angepasst.
Fein gemacht Markus. :D
Bis auf die unnötige Verwendung von Smarty. :roll: Hier hätte cTemplate locker gereicht.

Gruß aus Franken

Ortwin
ConLite 3.0.0-dev, alternatives und stabiles Update von Contenido 4.8.x unter PHP 8.x - Download und Repo auf Gitport.de
phpBO Search Advanced - das Suchwort-Plugin für CONTENIDO 4.9
Mein Entwickler-Blog
Faar
Beiträge: 1951
Registriert: Sa 8. Sep 2007, 16:23
Wohnort: Brandenburg
Hat sich bedankt: 15 Mal
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag von Faar »

Smartyitis ist ansteckend :twisted:
Fliegt der Bauer übers Dach, ist der Wind weißgott nicht schwach.
McHubi
Beiträge: 1223
Registriert: Do 18. Nov 2004, 23:06
Wohnort: Mettmann
Kontaktdaten:

Re: Passwort für Frontenduser - Änderung durch Frontenduser

Beitrag von McHubi »

Bis auf die unnötige Verwendung von Smarty. :roll: 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 :twisted:
:wink:
seamless-design.de
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.

Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)

Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)
Antworten