-
Notifications
You must be signed in to change notification settings - Fork 821
/
ChangePasswordForm.php
executable file
·54 lines (46 loc) · 1.37 KB
/
ChangePasswordForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?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');
}
}
}
?>