2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
|
2007-09-16 02:44:30 +02:00
|
|
|
/**
|
|
|
|
* Change password form
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
/**
|
|
|
|
* Standard Change Password Form
|
|
|
|
*/
|
|
|
|
class ChangePasswordForm extends Form {
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-09-16 02:44:30 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param Controller $controller The parent controller, necessary to
|
|
|
|
* create the appropriate form action tag.
|
|
|
|
* @param string $name The method on the controller that will return this
|
|
|
|
* form object.
|
|
|
|
* @param FieldSet|FormField $fields All of the fields in the form - a
|
|
|
|
* {@link FieldSet} of {@link FormField}
|
|
|
|
* objects.
|
|
|
|
* @param FieldSet|FormAction $actions All of the action buttons in the
|
|
|
|
* form - a {@link FieldSet} of
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function __construct($controller, $name, $fields = null, $actions = null) {
|
|
|
|
if(!$fields) {
|
2007-09-16 02:32:48 +02:00
|
|
|
$fields = new FieldSet();
|
|
|
|
if(Member::currentUser()) {
|
|
|
|
$fields->push(new EncryptField("OldPassword","Your old password"));
|
|
|
|
}
|
|
|
|
|
|
|
|
$fields->push(new EncryptField("NewPassword1", "New Password"));
|
|
|
|
$fields->push(new EncryptField("NewPassword2", "Confirm New Password"));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
if(!$actions) {
|
|
|
|
$actions = new FieldSet(
|
|
|
|
new FormAction("changePassword", "Change Password")
|
|
|
|
);
|
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
|
2007-09-16 02:44:30 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
/**
|
|
|
|
* Change the password
|
|
|
|
*
|
|
|
|
* @param array $data The user submitted data
|
|
|
|
*/
|
|
|
|
function changePassword(array $data) {
|
|
|
|
if($member = Member::currentUser()) {
|
|
|
|
// The user was logged in, check the current password
|
|
|
|
if($member->checkPassword($data['OldPassword']) == false) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->clearMessage();
|
2007-09-16 02:32:48 +02:00
|
|
|
$this->sessionMessage(
|
|
|
|
"Your current password does not match, please try again", "bad");
|
2007-07-19 12:40:28 +02:00
|
|
|
Director::redirectBack();
|
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!$member) {
|
|
|
|
if(Session::get('AutoLoginHash')) {
|
|
|
|
$member = Member::autoLoginHash(Session::get('AutoLoginHash'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The user is not logged in and no valid auto login hash is available
|
|
|
|
if(!$member) {
|
|
|
|
Session::clear('AutoLoginHash');
|
|
|
|
Director::redirect('loginpage');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
|
|
|
|
// Check the new password
|
|
|
|
if($data['NewPassword1'] == $data['NewPassword2']) {
|
|
|
|
$member->Password = $data['NewPassword1'];
|
|
|
|
$member->AutoLoginHash = null;
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
$member->sendinfo('changePassword',
|
|
|
|
array('CleartextPassword' => $data['NewPassword1']));
|
|
|
|
|
|
|
|
$this->clearMessage();
|
|
|
|
$this->sessionMessage(
|
|
|
|
"Your password has been changed, and a copy emailed to you.",
|
|
|
|
"good");
|
|
|
|
Session::clear('AutoLoginHash');
|
|
|
|
Director::redirect(Security::Link('login'));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$this->clearMessage();
|
|
|
|
$this->sessionMessage(
|
|
|
|
"Your have entered your new password differently, try again",
|
|
|
|
"bad");
|
|
|
|
Director::redirectBack();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
?>
|