[[!UpdateProfile &preHook=`UpdatePassword`]] [[$lgnupdateprofile]]
<?php $pword1 = $scriptProperties['fields']['password']; $pword2 = $scriptProperties['fields']['password_confirm']; if($pword1 == $pword2){ $errorMsg = 'they match'; }else{ $errorMsg = 'they dont match'; } $scriptProperties['hook']->errors['user'] = $errorMsg; return false; ?>
<? $user = $modx->getUser(); $output = "<p>"; $output .= $user->get('username') . "<br />"; $output .= $user->get('email') . "<br />"; $output .= $user->get('password') . "<br />"; $output .= "</p>"; $output .= "<p>"; $settings = $user->getSettings(); foreach($settings as $key => $value){ $output .= $key . ": " . $value . "<br />"; } $output .= "</p>"; return $output; ?>
$email = $user->getOne('Profile')->get('email'); $output .= "<p>".$email."</p>";
<?php /** * ChangePassword snippet **/ /* setup default properties */ /* verify authenticated status */ if (!$modx->user->hasSessionContext($modx->context->get('key'))) { $modx->sendUnauthorizedPage(); } /* get profile */ $profile = $modx->user->getOne('Profile'); if (empty($profile)) { $modx->log(modX::LOG_LEVEL_ERROR,'Could not find profile for user: '.$modx->user->get('username')); return ''; } $placeholders = $profile->toArray(); $modx->toPlaceholders($placeholders, 'chgPwd'); $error = false; if (!empty($_POST) && isset($_POST['updpword-btn'])) { if(strlen($_POST['new_password']) < 8){ $modx->toPlaceholder('error.password', '<p class="error">New password must be at least 8 characters</p>'); $error = true; } if($_POST['new_password'] != $_POST['password_confirm']){ $modx->toPlaceholder('error.password_confirm', '<p class="error">Passwords do not match!</p>'); $error = true; } if($_POST['old_password'] == ''){ $modx->toPlaceholder('error.old_password', '<p class="error">Please provide your existing password</p>'); $error = true; } if(!$error){ // no error messages set // update pword.. if($modx->user->changePassword($_POST['new_password'], $_POST['old_password'])){ $message = '<p class="success">Successfully updated password.</p>'; }else{ $message = '<p class="error">Could not update password!</p>'; } } $modx->toPlaceholder('error.message', '<p class="error">' . $message . '</p>'); } return ''; ?>
<div class="change-password"> [[+error.message]] <form class="form" action="[[~[[*id]]]]" method="post"> <label for="new_password">New password</label> <input type="password" name="new_password" id="new_password" /> [[+error.password]] <label for="password_confirm">Confirm password</label> <input type="password" name="password_confirm" id="password_confirm" /> [[+error.password_confirm]] <br /> <label for="old_password">Old password</label> <input type="password" name="old_password" id="old_password" /> [[+error.old_password]] <br /> <input type="submit" name="updpword-btn" value="Change password" /> </form> </div>