working demo
This commit is contained in:
parent
b194d2031d
commit
a8de581c09
6 changed files with 216 additions and 27 deletions
152
statics/selfservice/parent.html
Normal file
152
statics/selfservice/parent.html
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
<!-- FILEPATH: /D:/Git/satitm-sso-node/statics/selfservice/student.html -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<style>
|
||||
.parent-box {
|
||||
background-color: #f2f2f2;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
max-width: 400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.inner-box {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.linked-student {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#generate-token-btn {
|
||||
background-color: #007bff;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
#logout-btn {
|
||||
background-color: #dc3545;
|
||||
}
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div id="input-modal" style="display: none; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4);">
|
||||
<div style="background-color: #fefefe; margin: 20% auto; padding: 20px; border: 1px solid #888; width: 50%; border-radius: 10px; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);">
|
||||
<span id="input-close" style="color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;">×</span>
|
||||
<p>Please enter the link ID:</p>
|
||||
<input id="link-id-input" type="text">
|
||||
<button id="submit-btn">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="modal" style="display: none; position: fixed; z-index: 1; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.4);">
|
||||
<div style="background-color: #fefefe; margin: 20% auto; padding: 20px; border: 1px solid #888; width: 50%; border-radius: 10px; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);">
|
||||
<span id="close" style="color: #aaa; float: right; font-size: 28px; font-weight: bold; cursor: pointer;">×</span>
|
||||
<p id="modal-text" style="font-size: 18px; color: #333;"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="parent-box">
|
||||
<div class="inner-box">
|
||||
<h2>Parent Information</h2>
|
||||
<p><span id="parent-name">Name:</span> </p>
|
||||
<p><span id="parent-surname">Surname:</span> </p>
|
||||
<p><span id="parent-email">Email:</span> </p>
|
||||
</div>
|
||||
|
||||
<div class="linked-student">
|
||||
<h2>Linked Student</h2>
|
||||
<p><span id="linked-student-info"></span></p>
|
||||
</div>
|
||||
|
||||
<button id="generate-token-btn">Link a Student</button>
|
||||
|
||||
<a href="/selfservice/api/logout" style="text-decoration: none;">
|
||||
<button id="logout-btn">Logout</button>
|
||||
</a>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$.get('/selfservice/api/whoami')
|
||||
.done(function(response) {
|
||||
const upn = response.upn;
|
||||
$.get(`/selfservice/api/parent/${upn}`)
|
||||
.done(function(parent) {
|
||||
$('#parent-name').text(`Name: ${parent.first_name}`);
|
||||
$('#parent-surname').text(`Surname: ${parent.last_name}`);
|
||||
$('#parent-email').text(`Email: ${parent.username}`);
|
||||
// Linked student is in key "students" and is a list
|
||||
// format as
|
||||
// - Student 1
|
||||
// - Student 2
|
||||
// - Student 3
|
||||
let student_str = '';
|
||||
for (let i = 0; i < parent.students.length; i++) {
|
||||
student_str += `- ${parent.students[i]}`
|
||||
if (i < parent.students.length - 1) {
|
||||
student_str += '<br>';
|
||||
}
|
||||
}
|
||||
$('#linked-student-info').html(student_str);
|
||||
$('#generate-token-btn').click(function() {
|
||||
$('#input-modal').show();
|
||||
});
|
||||
$('#submit-btn').click(function() {
|
||||
const linkId = $('#link-id-input').val();
|
||||
if (linkId) {
|
||||
$.get(`/selfservice/api/parent/${upn}/add-student`, { 'pairing_code': linkId })
|
||||
.done(function() {
|
||||
showModal('Student linked successfully');
|
||||
$('#input-modal').hide();
|
||||
})
|
||||
.fail(function() {
|
||||
showModal('Failed to link student');
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.fail(function() {
|
||||
showModal('Session expired, please login again');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/selfservice';
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
})
|
||||
.fail(function() {
|
||||
showModal('Session expired, please login again');
|
||||
setTimeout(() => {
|
||||
window.location.href = '/selfservice';
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
function showModal(text) {
|
||||
$('#modal-text').text(text);
|
||||
$('#modal').show();
|
||||
}
|
||||
|
||||
$('#close').click(function() {
|
||||
$('#modal').hide();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Loading…
Add table
Add a link
Reference in a new issue