Browse Source

QR rotation dev - timer, rotate text password, expiry time margin setting (#414)

* Adding expiry time margin to setting and updating settings text.

* Add rotateqrcode to class structure

* Add submit password text to lang

* Form to allow users to enter rotating passwords

* Display text password on password.php

* Add timer for rotate password/qrcode on password.php
nwp90-nwp90-allsessionsreport
maksudr 5 years ago
committed by Dan Marsden
parent
commit
5e95c44185
  1. 14
      js/password/attendance_QRCodeRotate.js
  2. 2
      lang/en/attendance.php
  3. 8
      locallib.php
  4. 23
      renderer.php

14
js/password/attendance_QRCodeRotate.js

@ -3,7 +3,7 @@
* @copyright 2019 Maksud R * @copyright 2019 Maksud R
* @package mod_attendance * @package mod_attendance
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* *
*/ */
class attendance_QRCodeRotate { class attendance_QRCodeRotate {
@ -15,9 +15,11 @@ class attendance_QRCodeRotate {
this.qrCodeHTMLElement = ""; this.qrCodeHTMLElement = "";
} }
start(sessionId, qrCodeHTMLElement) { start(sessionId, qrCodeHTMLElement, textPasswordHTMLElement, timerHTMLElement) {
this.sessionId = sessionId; this.sessionId = sessionId;
this.qrCodeHTMLElement = qrCodeHTMLElement; this.qrCodeHTMLElement = qrCodeHTMLElement;
this.textPasswordHTMLElement = textPasswordHTMLElement;
this.timerHTMLElement = timerHTMLElement;
this.fetchAndRotate(); this.fetchAndRotate();
} }
@ -36,6 +38,12 @@ class attendance_QRCodeRotate {
var qrcodeurl = document.URL.substr(0,document.URL.lastIndexOf('/')) + '/attendance.php?qrpass=' + password + '&sessid=' + this.sessionId; var qrcodeurl = document.URL.substr(0,document.URL.lastIndexOf('/')) + '/attendance.php?qrpass=' + password + '&sessid=' + this.sessionId;
this.qrCodeInstance.clear(); this.qrCodeInstance.clear();
this.qrCodeInstance.makeCode(qrcodeurl); this.qrCodeInstance.makeCode(qrcodeurl);
// display new password
this.textPasswordHTMLElement.innerHTML = '<h2>'+password+'</h2>';
}
updateTimer(timeLeft) {
this.timerHTMLElement.innerHTML = '<h3>Time left: '+timeLeft+'</h3>';
} }
startRotating() { startRotating() {
@ -53,6 +61,8 @@ class attendance_QRCodeRotate {
location.reload(true); location.reload(true);
} else { } else {
parent.changeQRCode(found.password); parent.changeQRCode(found.password);
parent.updateTimer(found.expirytime - Math.round(new Date().getTime() / 1000));
} }
}, 1000); }, 1000);

2
lang/en/attendance.php

@ -485,6 +485,8 @@ $string['studentscanmarksessiontime_desc'] = 'If checked students can only recor
$string['studentscanmarksessiontimeend'] = 'Session end (minutes)'; $string['studentscanmarksessiontimeend'] = 'Session end (minutes)';
$string['studentscanmarksessiontimeend_desc'] = 'If the session does not have an end time, how many minutes should the session be available for students to record their attendance.'; $string['studentscanmarksessiontimeend_desc'] = 'If the session does not have an end time, how many minutes should the session be available for students to record their attendance.';
$string['submitattendance'] = 'Submit attendance'; $string['submitattendance'] = 'Submit attendance';
$string['submitpassword'] = 'Submit password';
$string['submit'] = 'Submit';
$string['subnet'] = 'Subnet'; $string['subnet'] = 'Subnet';
$string['subnetactivitylevel'] = 'Allow subnet config at activity level'; $string['subnetactivitylevel'] = 'Allow subnet config at activity level';
$string['subnetactivitylevel_desc'] = 'If enabled, teachers can override the default subnet at the activity level when creating an attendance. Otherwise the site default will be used when creating a session.'; $string['subnetactivitylevel_desc'] = 'If enabled, teachers can override the default subnet at the activity level when creating an attendance. Otherwise the site default will be used when creating a session.';

8
locallib.php

@ -1139,7 +1139,6 @@ function attendance_generate_passwords($session) {
* @param stdClass $session * @param stdClass $session
*/ */
function attendance_renderqrcoderotate($session) { function attendance_renderqrcoderotate($session) {
echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
// load requered js // load requered js
echo html_writer::tag('script', '', echo html_writer::tag('script', '',
[ [
@ -1153,12 +1152,17 @@ function attendance_renderqrcoderotate($session) {
'type' => 'text/javascript' 'type' => 'text/javascript'
] ]
); );
echo html_writer::tag('div', '', ['id' => 'rotate-time']); // div to display timer
echo html_writer::tag('h3', get_string('passwordgrp', 'attendance'));
echo html_writer::tag('div', '', ['id' => 'text-password']); // div to display password
echo html_writer::tag('h3', get_string('qrcode', 'attendance'));
echo html_writer::tag('div', '', ['id' => 'qrcode']); // div to display qr code echo html_writer::tag('div', '', ['id' => 'qrcode']); // div to display qr code
// js to start the password manager // js to start the password manager
echo ' echo '
<script type="text/javascript"> <script type="text/javascript">
let qrCodeRotate = new attendance_QRCodeRotate(); let qrCodeRotate = new attendance_QRCodeRotate();
qrCodeRotate.start(' . $session->id . ', document.getElementById("qrcode")); qrCodeRotate.start(' . $session->id . ', document.getElementById("qrcode"), document.getElementById("text-password"),
document.getElementById("rotate-time"));
</script>'; </script>';
} }

23
renderer.php

@ -1121,12 +1121,23 @@ class mod_attendance_renderer extends plugin_renderer_base {
} else { } else {
list($canmark, $reason) = attendance_can_student_mark($sess, false); list($canmark, $reason) = attendance_can_student_mark($sess, false);
if ($canmark) { if ($canmark) {
// Student can mark their own attendance. if ($sess->rotateqrcode == 1) {
// URL to the page that lets the student modify their attendance. $url = new moodle_url('/mod/attendance/attendance.php');
$output = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sessid',
$url = new moodle_url('/mod/attendance/attendance.php', 'value' => $sess->id));
array('sessid' => $sess->id, 'sesskey' => sesskey())); $output .= html_writer::empty_tag('input', array('type' => 'text', 'name' => 'qrpass',
$cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance'))); 'placeholder' => "Enter password"));
$output .= html_writer::empty_tag('input', array('type' => 'submit',
'value' => get_string('submit'),
'class' => 'btn btn-secondary'));
$cell = new html_table_cell(html_writer::tag('form', $output, array('action' => $url->out(), 'method' => 'get')));
} else {
// Student can mark their own attendance.
// URL to the page that lets the student modify their attendance.
$url = new moodle_url('/mod/attendance/attendance.php',
array('sessid' => $sess->id, 'sesskey' => sesskey()));
$cell = new html_table_cell(html_writer::link($url, get_string('submitattendance', 'attendance')));
}
$cell->colspan = 3; $cell->colspan = 3;
$row->cells[] = $cell; $row->cells[] = $cell;
} else { // Student cannot mark their own attendace. } else { // Student cannot mark their own attendace.

Loading…
Cancel
Save