summaryrefslogtreecommitdiff
path: root/app/php/components/PasswordChange.php
blob: 1224f33ec89e9ec959636bc748a355de6fa83b69 (plain)
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
<?php

Prado::using('Application.user.DbUser');

class PasswordChange extends TTemplateControl {

    public function getUserToChange() {
        return $this->getControlState('user');
    }

    public function setUserToChange(DbUser $user) {
        if ($user->IsGuest) {
            throw new TInvalidDataValueException(
                'Password change impossible for guest user'
            );
        }
        $this->setControlState('user', $user);
    }

    public function checkPassword($sender, $param) {
        $param->IsValid = DbUser::verifyPassword(
            $this->Password->Text, $this->UserToChange->DbRecord->Password
        );
    }

    public function changePassword($sender, $param) {
        $this->SuccessMessage->Visible = FALSE;
        if ($this->Page->IsValid) {
            $this->UserToChange->DbRecord->Password = DbUser::generatePassword(
                $this->NewPassword->Text
            );
            $this->UserToChange->DbRecord->save();
            $this->SuccessMessage->Visible = TRUE;
        }
    }

}

?>