silverstripe-framework/security/ChangePasswordForm.php
Hayden Smith 4a5d9b03f8 Moved Sapphire module to open source path
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@39001 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-07-19 10:40:28 +00:00

54 lines
1.4 KiB
PHP
Executable File

<?php
/**
* Standard Change Password Form
*/
class ChangePasswordForm extends Form {
function __construct($controller, $name, $fields = null, $actions = null) {
if(!$fields) {
$fields = new FieldSet(
new EncryptField("OldPassword","Your old password"),
new EncryptField("NewPassword1", "New Password"),
new EncryptField("NewPassword2", "Confirm New Password")
);
}
if(!$actions) {
$actions = new FieldSet(
new FormAction("changePassword", "Change Password")
);
}
parent::__construct($controller, $name, $fields, $actions);
}
function changePassword($data){
if($member = Member::currentUser()){
if($data['OldPassword'] != $member->Password){
$this->clearMessage();
$this->sessionMessage("Your current password does not match, please try again", "bad");
Director::redirectBack();
}else if($data[NewPassword1] == $data[NewPassword2]){
$member->Password = $data[NewPassword1] ;
$member->sendinfo('changePassword');
$member->write();
$this->clearMessage();
$this->sessionMessage("Your password has been changed, and a copy emailed to you.", "good");
Director::redirectBack();
}
else{
$this->clearMessage();
$this->sessionMessage("Your have entered your new password differently, try again", "bad");
Director::redirectBack();
}
}
else {
Director::redirect('loginpage');
}
}
}
?>