Subversion Repositories oidplus

Rev

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

Rev 1086 Rev 1116
Line 23... Line 23...
23
\defined('INSIDE_OIDPLUS') or die;
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
24
// phpcs:enable PSR1.Files.SideEffects
25
 
25
 
26
class OIDplusPageRaInvite extends OIDplusPagePluginRa {
26
class OIDplusPageRaInvite extends OIDplusPagePluginRa {
27
 
27
 
-
 
28
        /**
-
 
29
         * @param string $actionID
-
 
30
         * @param array $params
-
 
31
         * @return int[]
-
 
32
         * @throws OIDplusException
-
 
33
         * @throws OIDplusMailException
-
 
34
         */
28
        public function action($actionID, $params) {
35
        public function action(string $actionID, array $params): array {
29
                if ($actionID == 'invite_ra') {
36
                if ($actionID == 'invite_ra') {
30
                        $email = $params['email'];
37
                        $email = $params['email'];
31
 
38
 
32
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
39
                        if (!OIDplus::mailUtils()->validMailAddress($email)) {
33
                                throw new OIDplusException(_L('Invalid email address'));
40
                                throw new OIDplusException(_L('Invalid email address'));
Line 85... Line 92...
85
                        $ra = new OIDplusRA($email);
92
                        $ra = new OIDplusRA($email);
86
                        $ra->register_ra($password1);
93
                        $ra->register_ra($password1);
87
 
94
 
88
                        return array("status" => 0);
95
                        return array("status" => 0);
89
                } else {
96
                } else {
90
                        throw new OIDplusException(_L('Unknown action ID'));
97
                        return parent::action($actionID, $params);
91
                }
98
                }
92
        }
99
        }
93
 
100
 
-
 
101
        /**
-
 
102
         * @param bool $html
-
 
103
         * @return void
-
 
104
         * @throws OIDplusException
-
 
105
         */
94
        public function init($html=true) {
106
        public function init(bool $html=true) {
95
                OIDplus::config()->prepareConfigKey('max_ra_invite_time', 'Max RA invite time in seconds (0 = infinite)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
107
                OIDplus::config()->prepareConfigKey('max_ra_invite_time', 'Max RA invite time in seconds (0 = infinite)', '0', OIDplusConfig::PROTECTION_EDITABLE, function($value) {
96
                        if (!is_numeric($value) || ($value < 0)) {
108
                        if (!is_numeric($value) || ($value < 0)) {
97
                                throw new OIDplusException(_L('Please enter a valid value.'));
109
                                throw new OIDplusException(_L('Please enter a valid value.'));
98
                        }
110
                        }
99
                });
111
                });
Line 102... Line 114...
102
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
114
                                throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).'));
103
                        }
115
                        }
104
                });
116
                });
105
        }
117
        }
106
 
118
 
-
 
119
        /**
-
 
120
         * @param string $id
-
 
121
         * @param array $out
-
 
122
         * @param bool $handled
-
 
123
         * @return void
-
 
124
         * @throws OIDplusException
-
 
125
         */
107
        public function gui($id, &$out, &$handled) {
126
        public function gui(string $id, array &$out, bool &$handled) {
108
                if (explode('$',$id)[0] == 'oidplus:invite_ra') {
127
                if (explode('$',$id)[0] == 'oidplus:invite_ra') {
109
                        $handled = true;
128
                        $handled = true;
110
 
129
 
111
                        $email = explode('$',$id)[1];
130
                        $email = explode('$',$id)[1];
112
                        $origin = explode('$',$id)[2];
131
                        $origin = explode('$',$id)[2];
Line 179... Line 198...
179
                                }
198
                                }
180
                        }
199
                        }
181
                }
200
                }
182
        }
201
        }
183
 
202
 
-
 
203
        /**
-
 
204
         * @param array $json
-
 
205
         * @param string|null $ra_email
-
 
206
         * @param bool $nonjs
-
 
207
         * @param string $req_goto
-
 
208
         * @return bool
-
 
209
         */
184
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
210
        public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool {
185
                //if (!$ra_email) return false;
211
                //if (!$ra_email) return false;
186
                //if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false;
212
                //if (!OIDplus::authUtils()->isRaLoggedIn($ra_email) && !OIDplus::authUtils()->isAdminLoggedIn()) return false;
187
 
213
 
188
                return false;
214
                return false;
189
        }
215
        }
190
 
216
 
-
 
217
        /**
-
 
218
         * @param $email
-
 
219
         * @return void
-
 
220
         * @throws OIDplusException
-
 
221
         */
191
        private function inviteSecurityCheck($email) {
222
        private function inviteSecurityCheck($email) {
192
                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
223
                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
193
                if ($res->any()) {
224
                if ($res->any()) {
194
                        throw new OIDplusException(_L('This RA is already registered and does not need to be invited.'));
225
                        throw new OIDplusException(_L('This RA is already registered and does not need to be invited.'));
195
                }
226
                }
Line 198... Line 229...
198
                        // Check if the RA may invite the user (i.e. the they are the parent of an OID of that person)
229
                        // Check if the RA may invite the user (i.e. the they are the parent of an OID of that person)
199
                        $ok = false;
230
                        $ok = false;
200
                        $res = OIDplus::db()->query("select parent from ###objects where ra_email = ?", array($email));
231
                        $res = OIDplus::db()->query("select parent from ###objects where ra_email = ?", array($email));
201
                        while ($row = $res->fetch_array()) {
232
                        while ($row = $res->fetch_array()) {
202
                                $objParent = OIDplusObject::parse($row['parent']);
233
                                $objParent = OIDplusObject::parse($row['parent']);
203
                                if (is_null($objParent)) throw new OIDplusException(_L('Type of %1 unknown',$row['parent']));
234
                                if (!$objParent) throw new OIDplusException(_L('Type of %1 unknown',$row['parent']));
204
                                if ($objParent->userHasWriteRights()) {
235
                                if ($objParent->userHasWriteRights()) {
205
                                        $ok = true;
236
                                        $ok = true;
206
                                }
237
                                }
207
                        }
238
                        }
208
                        if (!$ok) {
239
                        if (!$ok) {
209
                                throw new OIDplusException(_L('You may not invite this RA. Maybe you need to <a %1>log in</a> again.',OIDplus::gui()->link('oidplus:login')));
240
                                throw new OIDplusException(_L('You may not invite this RA. Maybe you need to <a %1>log in</a> again.',OIDplus::gui()->link('oidplus:login')));
210
                        }
241
                        }
211
                }
242
                }
212
        }
243
        }
213
 
244
 
-
 
245
        /**
-
 
246
         * @param $email
-
 
247
         * @return string
-
 
248
         * @throws OIDplusException
-
 
249
         */
214
        private function getInvitationText($email) {
250
        private function getInvitationText($email): string {
215
                $list_of_oids = array();
251
                $list_of_oids = array();
216
                $res = OIDplus::db()->query("select id from ###objects where ra_email = ?", array($email));
252
                $res = OIDplus::db()->query("select id from ###objects where ra_email = ?", array($email));
217
                while ($row = $res->fetch_array()) {
253
                while ($row = $res->fetch_array()) {
218
                        $list_of_oids[] = $row['id'];
254
                        $list_of_oids[] = $row['id'];
219
                }
255
                }
Line 229... Line 265...
229
                // {{ACTIVATE_URL}} will be resolved in ajax.php
265
                // {{ACTIVATE_URL}} will be resolved in ajax.php
230
 
266
 
231
                return $message;
267
                return $message;
232
        }
268
        }
233
 
269
 
-
 
270
        /**
-
 
271
         * @param string $request
-
 
272
         * @return array|false
-
 
273
         */
234
        public function tree_search($request) {
274
        public function tree_search(string $request) {
235
                return false;
275
                return false;
236
        }
276
        }
237
}
277
}