Merge pull request #34 from wulkanowy/feature/student_data

Student data
This commit is contained in:
Zaptyp 2021-01-30 21:51:42 +01:00 committed by GitHub
commit ba8bade697
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 12 deletions

31
app/API/student_data.py Normal file
View file

@ -0,0 +1,31 @@
import json
import requests
def get_student_data(register_id, register_r, oun, s):
cookies = s
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
cookies.update({
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
"idBiezacyDziennikWychowankowie": f"{register_r['data'][0]['IdWychowankowieDziennik']}",
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
})
else:
cookies.update({
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
})
headers = {
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*',
'Connection': 'keep-alive',
"User-Agent": "Wulkanowy-web :)"
}
student_data = requests.post(f'{oun}/Uczen.mvc/Get', headers=headers, cookies=cookies)
return student_data.json()

View file

@ -19,6 +19,7 @@ from .API.homeworks import get_homeworks
from .API.mobile_access import get_registered_devices, register_device
from .API.school_data import get_school_data
from .API.dashboard import get_dashboard
from .API.student_data import get_student_data
from .decrypt import decrypt_cookies
#API
@ -300,5 +301,19 @@ def message_content(request, *args, **kwargs):
message_id = data['message_id']
content = get_message_content(register_id, register_r, oun, s, date, school_year, symbol, message_id)
return JsonResponse(content, safe=False)
else:
return redirect('../')
def student_data(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
register_r = data['data']['register_r']
oun = data['data']['oun']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
data = get_student_data(register_id, register_r, oun, s)
return JsonResponse(data)
else:
return redirect('../')

View file

@ -0,0 +1,22 @@
const student_data_ = document.querySelector('#student_data_');
myStorage = window.sessionStorage;
const getStudentData = () => {
document.querySelector('#content').innerHTML = 'Here is student data (in my imagination)';
cookies_data = sessionStorage.getItem('cookies_data');
csrfcookie_ = sessionStorage.getItem('csrfcookie');
fetch(url = '../api/student_data', {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfcookie_
},
body: cookies_data
}).then(response => response.json()).then(data => {
console.log(data)
})
}
student_data_.addEventListener('click', getStudentData)

View file

@ -6,17 +6,6 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="{% static 'frontend/css/start.css' %}" type="text/css" />
<script src="{% static 'frontend/js/start.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/dashboard.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/dist/out-grades.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/timetable.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/exams.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/notes.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/attendance.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/homeworks.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/dist/out-messages.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/mobile_access.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/school_data.js' %}" type="text/javascript" defer></script>
<link rel="shortcut icon" href="{% static 'frontend/images/27146352.png' %}">
<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Lora:wght@500&display=swap" rel="stylesheet">
@ -55,6 +44,7 @@
<li><a id="notes_" class='option'><i class="material-icons">emoji_events</i>Uwagi i Osiągnięcia</a></li>
<li><a id="mobile_access_" class='option'><i class="material-icons">devices</i>Dostęp Mobilny</a></li>
<li><a id="school_data_" class='option'><i class="material-icons">business</i>Szkoła i Nauczyciele</a></li>
<li><a id="student_data_" class='option'><i class="material-icons">assignment_ind</i>Dane Ucznia</a></li>
<li><a id="messages_" class="dropdown-trigger" data-target="dropdown1"><i class="material-icons">email</i>Wiadomości</a></li>
<ul id='dropdown1' class='dropdown-content'>
<li><a id='received_' class='option'>Odebrane</a></li>
@ -91,5 +81,17 @@
}
</script>
<script src="{% static 'frontend/js/start.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/dashboard.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/dist/out-grades.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/timetable.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/exams.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/notes.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/attendance.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/homeworks.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/dist/out-messages.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/mobile_access.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/school_data.js' %}" type="text/javascript" defer></script>
<script src="{% static 'frontend/js/student_data.js' %}" type="text/javascript" defer></script>
</body>
</html>

View file

@ -115,6 +115,10 @@ def get_data_test(client, cookies_data, assertEquals):
assertEquals(response.status_code, 200)
recipients = response.json()['addressee']['data']
#STUDENT DATA
response = client.post(reverse('student_data'), content_type='application/xml', data=json.dumps(cookies_data))
assertEquals(response.status_code, 200)
#SEND MESSAGE
for recipient in recipients:
send_data = {

View file

@ -17,7 +17,7 @@ from django.urls import path
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from frontend.views import default_view, content_view, account_manager_view
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients, send, message_content
from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients, send, message_content, student_data
urlpatterns = [
#views
@ -34,6 +34,7 @@ urlpatterns = [
path('api/notes', notes, name='notes'),
path('api/school_data', school_data, name='school_data'),
path('api/dashboard', dashboard, name='dashboard'),
path('api/student_data', student_data, name='student_data'),
#MOBILE ACCESS
path('api/mobile/registered', registered_devices, name='registered_devices'),
path('api/mobile/register', register_device_, name='register_device'),