Subversion Repositories oidplus

Rev

Rev 328 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 328 Rev 360
Line 23... Line 23...
23
                if ($actionID == 'change_ra_password') {
23
                if ($actionID == 'change_ra_password') {
24
                        $email = $params['email'];
24
                        $email = $params['email'];
25
 
25
 
26
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
26
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
27
                        if ($res->num_rows() == 0) {
27
                        if ($res->num_rows() == 0) {
28
                                throw new OIDplusException('RA does not exist');
28
                                throw new OIDplusException(_L('RA does not exist'));
29
                        }
29
                        }
30
 
30
 
31
                        if (!OIDplus::authUtils()::isRaLoggedIn($email) && !OIDplus::authUtils()::isAdminLoggedIn()) {
31
                        if (!OIDplus::authUtils()::isRaLoggedIn($email) && !OIDplus::authUtils()::isAdminLoggedIn()) {
32
                                throw new OIDplusException('Authentication error. Please log in as the RA or admin to update its data.');
32
                                throw new OIDplusException(_L('Authentication error. Please log in as admin, or as the RA to update its data.'));
33
                        }
33
                        }
34
 
34
 
35
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
35
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
36
                                $old_password = $params['old_password'];
36
                                $old_password = $params['old_password'];
37
                        }
37
                        }
38
                        $password1 = $params['new_password1'];
38
                        $password1 = $params['new_password1'];
39
                        $password2 = $params['new_password2'];
39
                        $password2 = $params['new_password2'];
40
 
40
 
41
                        if ($password1 !== $password2) {
41
                        if ($password1 !== $password2) {
42
                                throw new OIDplusException('Passwords are not equal');
42
                                throw new OIDplusException(_L('Passwords do not match'));
43
                        }
43
                        }
44
 
44
 
45
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
45
                        if (strlen($password1) < OIDplus::config()->getValue('ra_min_password_length')) {
-
 
46
                                $minlen = OIDplus::config()->getValue('ra_min_password_length');
46
                                throw new OIDplusException('New password is too short. Minimum password length: '.OIDplus::config()->getValue('ra_min_password_length'));
47
                                throw new OIDplusException(_L('New password is too short. Minimum password length: %1',$minlen));
47
                        }
48
                        }
48
 
49
 
49
                        $ra = new OIDplusRA($email);
50
                        $ra = new OIDplusRA($email);
50
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
51
                        if (!OIDplus::authUtils()::isAdminLoggedIn()) {
51
                                if (!$ra->checkPassword($old_password)) {
52
                                if (!$ra->checkPassword($old_password)) {
52
                                        throw new OIDplusException('Old password incorrect');
53
                                        throw new OIDplusException(_L('Old password incorrect'));
53
                                }
54
                                }
54
                        }
55
                        }
55
                        OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Password of RA '$email' changed");
56
                        OIDplus::logger()->log("[?WARN/!OK]RA($email)?/[?INFO/!OK]A?", "Password of RA '$email' changed");
56
                        $ra->change_password($password1);
57
                        $ra->change_password($password1);
57
 
58
 
58
                        return array("status" => 0);
59
                        return array("status" => 0);
59
                } else {
60
                } else {
60
                        throw new OIDplusException("Unknown action ID");
61
                        throw new OIDplusException(_L('Unknown action ID'));
61
                }
62
                }
62
        }
63
        }
63
 
64
 
64
        public function init($html=true) {
65
        public function init($html=true) {
65
                // Nothing
66
                // Nothing
Line 69... Line 70...
69
                if (explode('$',$id)[0] == 'oidplus:change_ra_password') {
70
                if (explode('$',$id)[0] == 'oidplus:change_ra_password') {
70
                        $handled = true;
71
                        $handled = true;
71
                       
72
 
72
                        $ra_email = explode('$',$id)[1];
73
                        $ra_email = explode('$',$id)[1];
73
 
74
 
74
                        $out['title'] = 'Change RA password';
75
                        $out['title'] = _L('Change RA password');
75
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
76
                        $out['icon'] = file_exists(__DIR__.'/icon_big.png') ? OIDplus::webpath(__DIR__).'icon_big.png' : '';
76
 
77
 
77
                        if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) {
78
                        if (!OIDplus::authUtils()::isRaLoggedIn($ra_email) && !OIDplus::authUtils()::isAdminLoggedIn()) {
78
                                $out['icon'] = 'img/error_big.png';
79
                                $out['icon'] = 'img/error_big.png';
79
                                $out['text'] = '<p>You need to <a '.OIDplus::gui()->link('oidplus:login').'>log in</a> as the requested RA <b>'.htmlentities($ra_email).'</b>.</p>';
80
                                $out['text'] = '<p>'._L('You need to <a %1>log in</a> as the requested RA %2.',OIDplus::gui()->link('oidplus:login'),'<b>'.htmlentities($ra_email).'</b>').'</p>';
80
                                return;
81
                                return;
81
                        }
82
                        }
82
 
83
 
83
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email));
84
                        $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email));
84
                        if ($res->num_rows() == 0) {
85
                        if ($res->num_rows() == 0) {
85
                                $out['icon'] = 'img/error_big.png';
86
                                $out['icon'] = 'img/error_big.png';
86
                                $out['text'] = 'RA <b>'.htmlentities($ra_email).'</b> does not exist';
87
                                $out['text'] = _L('RA "%1" does not exist','<b>'.htmlentities($ra_email).'</b>');
87
                                return;
88
                                return;
88
                        }
89
                        }
89
 
90
 
90
                        $out['text'] .= '<form id="raChangePasswordForm" onsubmit="return raChangePasswordFormOnSubmit();">';
91
                        $out['text'] .= '<form id="raChangePasswordForm" onsubmit="return raChangePasswordFormOnSubmit();">';
91
                        $out['text'] .= '<input type="hidden" id="email" value="'.htmlentities($ra_email).'"/><br>';
92
                        $out['text'] .= '<input type="hidden" id="email" value="'.htmlentities($ra_email).'"/><br>';
92
                        $out['text'] .= '<div><label class="padding_label">E-Mail:</label><b>'.htmlentities($ra_email).'</b></div>';
93
                        $out['text'] .= '<div><label class="padding_label">'._L('E-Mail').':</label><b>'.htmlentities($ra_email).'</b></div>';
93
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
94
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
94
                                $out['text'] .= '<div><label class="padding_label">Old password:</label><i>Admin can change the password without verification of the old password.</i></div>';
95
                                $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><i>'._L('Admin can change the password without verification of the old password.').'</i></div>';
95
                        } else {
96
                        } else {
96
                                $out['text'] .= '<div><label class="padding_label">Old password:</label><input type="password" id="old_password" value=""/></div>';
97
                                $out['text'] .= '<div><label class="padding_label">'._L('Old password').':</label><input type="password" id="old_password" value=""/></div>';
97
                        }
98
                        }
98
                        $out['text'] .= '<div><label class="padding_label">New password:</label><input type="password" id="new_password1" value=""/></div>';
99
                        $out['text'] .= '<div><label class="padding_label">'._L('New password').':</label><input type="password" id="new_password1" value=""/></div>';
99
                        $out['text'] .= '<div><label class="padding_label">Repeat:</label><input type="password" id="new_password2" value=""/></div>';
100
                        $out['text'] .= '<div><label class="padding_label">'._L('Repeat').':</label><input type="password" id="new_password2" value=""/></div>';
100
                        $out['text'] .= '<br><input type="submit" value="Change password"></form>';
101
                        $out['text'] .= '<br><input type="submit" value="'._L('Change password').'"></form>';
101
                }
102
                }
102
        }
103
        }
103
 
104
 
104
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
105
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
105
                if (!$ra_email) return false;
106
                if (!$ra_email) return false;
Line 112... Line 113...
112
                }
113
                }
113
 
114
 
114
                $json[] = array(
115
                $json[] = array(
115
                        'id' => 'oidplus:change_ra_password$'.$ra_email,
116
                        'id' => 'oidplus:change_ra_password$'.$ra_email,
116
                        'icon' => $tree_icon,
117
                        'icon' => $tree_icon,
117
                        'text' => 'Change password'
118
                        'text' => _L('Change password')
118
                );
119
                );
119
 
120
 
120
                return true;
121
                return true;
121
        }
122
        }
122
 
123