Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 17... Línea 17...
17
namespace factor_sms;
17
namespace factor_sms;
Línea 18... Línea 18...
18
 
18
 
19
use moodle_url;
19
use moodle_url;
20
use stdClass;
20
use stdClass;
-
 
21
use tool_mfa\local\factor\object_factor_base;
Línea 21... Línea 22...
21
use tool_mfa\local\factor\object_factor_base;
22
use tool_mfa\local\secret_manager;
22
 
23
 
23
/**
24
/**
24
 * SMS Factor implementation.
25
 * SMS Factor implementation.
Línea 166... Línea 167...
166
        $editphonenumber = \html_writer::link(
167
        $editphonenumber = \html_writer::link(
167
            new \moodle_url('/admin/tool/mfa/factor/sms/editphonenumber.php', ['sesskey' => sesskey()]),
168
            new \moodle_url('/admin/tool/mfa/factor/sms/editphonenumber.php', ['sesskey' => sesskey()]),
168
            get_string('editphonenumber', 'factor_sms'),
169
            get_string('editphonenumber', 'factor_sms'),
169
            ['class' => 'btn btn-secondary', 'type' => 'button']);
170
            ['class' => 'btn btn-secondary', 'type' => 'button']);
Línea 170... Línea 171...
170
 
171
 
Línea 171... Línea 172...
171
        $mform->addElement('html', \html_writer::tag('div', $editphonenumber, ['class' => 'float-sm-left col-md-4']));
172
        $mform->addElement('html', \html_writer::tag('div', $editphonenumber, ['class' => 'float-sm-start col-md-4']));
172
 
173
 
Línea 173... Línea 174...
173
        // Disable the form check prompt.
174
        // Disable the form check prompt.
Línea 229... Línea 230...
229
        global $SESSION;
230
        global $SESSION;
230
        if (!empty($SESSION->tool_mfa_sms_number)) {
231
        if (!empty($SESSION->tool_mfa_sms_number)) {
231
            unset($SESSION->tool_mfa_sms_number);
232
            unset($SESSION->tool_mfa_sms_number);
232
        }
233
        }
233
        // Clean temp secrets code.
234
        // Clean temp secrets code.
234
        $secretmanager = new \tool_mfa\local\secret_manager('sms');
235
        $secretmanager = new secret_manager('sms');
235
        $secretmanager->cleanup_temp_secrets();
236
        $secretmanager->cleanup_temp_secrets();
236
    }
237
    }
Línea 237... Línea 238...
237
 
238
 
238
    /**
239
    /**
Línea 321... Línea 322...
321
     * Returns the information about factor availability.
322
     * Returns the information about factor availability.
322
     *
323
     *
323
     * @return bool
324
     * @return bool
324
     */
325
     */
325
    public function is_enabled(): bool {
326
    public function is_enabled(): bool {
326
        if (empty(get_config('factor_sms', 'gateway'))) {
-
 
327
            return false;
-
 
328
        }
-
 
329
 
-
 
330
        $class = '\factor_sms\local\smsgateway\\' . get_config('factor_sms', 'gateway');
-
 
331
        if (!call_user_func($class . '::is_gateway_enabled')) {
-
 
332
            return false;
-
 
333
        }
-
 
334
        return parent::is_enabled();
327
        return parent::is_enabled();
335
    }
328
    }
Línea 336... Línea 329...
336
 
329
 
337
    /**
330
    /**
Línea 356... Línea 349...
356
     * Decides if the setup buttons should be shown on the preferences page.
349
     * Decides if the setup buttons should be shown on the preferences page.
357
     *
350
     *
358
     * @return bool
351
     * @return bool
359
     */
352
     */
360
    public function show_setup_buttons(): bool {
353
    public function show_setup_buttons(): bool {
-
 
354
        if (get_config('factor_sms', 'smsgateway') > 0) {
361
        return true;
355
            return true;
-
 
356
        }
-
 
357
        return false;
362
    }
358
    }
Línea 363... Línea 359...
363
 
359
 
364
    /**
360
    /**
365
     * Returns true if factor class has factor records that might be revoked.
361
     * Returns true if factor class has factor records that might be revoked.
Línea 410... Línea 406...
410
            'url' => $url->get_host(),
406
            'url' => $url->get_host(),
411
            'code' => $secret,
407
            'code' => $secret,
412
        ];
408
        ];
413
        $message = get_string('smsstring', 'factor_sms', $content);
409
        $message = get_string('smsstring', 'factor_sms', $content);
Línea 414... Línea 410...
414
 
410
 
415
        $class = '\factor_sms\local\smsgateway\\' . get_config('factor_sms', 'gateway');
411
        $manager = \core\di::get(\core_sms\manager::class);
416
        $gateway = new $class();
412
        $manager->send(
-
 
413
            recipientnumber: $phonenumber,
-
 
414
            content: $message,
-
 
415
            component: 'factor_sms',
-
 
416
            messagetype: 'mfa',
-
 
417
            recipientuserid: null,
-
 
418
            issensitive: true,
-
 
419
            async: false,
-
 
420
            gatewayid: get_config('factor_sms', 'smsgateway'),
417
        $gateway->send_sms_message($message, $phonenumber);
421
        );
Línea 418... Línea 422...
418
    }
422
    }
419
 
423
 
420
    /**
424
    /**
421
     * Verifies entered code against stored DB record.
425
     * Verifies entered code against stored DB record.
422
     *
426
     *
423
     * @param string $enteredcode
427
     * @param string $enteredcode
424
     * @return bool
428
     * @return bool
425
     */
429
     */
426
    private function check_verification_code(string $enteredcode): bool {
430
    private function check_verification_code(string $enteredcode): bool {
Línea 427... Línea 431...
427
        return ($this->secretmanager->validate_secret($enteredcode) === \tool_mfa\local\secret_manager::VALID) ? true : false;
431
        return $this->secretmanager->validate_secret($enteredcode) === secret_manager::VALID;
428
    }
432
    }
429
 
433
 
Línea 451... Línea 455...
451
 
455
 
Línea 452... Línea 456...
452
        $phonenumber = $this->get_phonenumber();
456
        $phonenumber = $this->get_phonenumber();
453
 
457
 
454
        if (empty($phonenumber)) {
-
 
455
            return get_string('errorsmssent', 'factor_sms');
-
 
456
        } else {
458
        if (empty($phonenumber)) {
-
 
459
            return get_string('errorsmssent', 'factor_sms');
-
 
460
        }
457
            return get_string('logindesc', 'factor_' . $this->name, $phonenumber);
461
 
458
        }
462
        return get_string('logindesc', 'factor_' . $this->name, $phonenumber);