diff --git a/app/API/school_data.py b/app/API/school_data.py new file mode 100644 index 0000000..f018919 --- /dev/null +++ b/app/API/school_data.py @@ -0,0 +1,31 @@ +import json +import requests + +def get_school_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 :)" + } + + school_data = requests.post(oun+'/SzkolaINauczyciele.mvc/Get', headers=headers, cookies=cookies) + + return school_data.json() \ No newline at end of file diff --git a/app/views.py b/app/views.py index f3c06d9..a23207d 100644 --- a/app/views.py +++ b/app/views.py @@ -15,6 +15,7 @@ from .API.attendance import get_attendance from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages from .API.homeworks import get_homeworks from .API.mobile_access import get_registered_devices, register_device +from .API.school_data import get_school_data #views def default_view(request, *args, **kwargs): @@ -161,7 +162,7 @@ def received_messages(request, *args, **kwargs): school_year = data['data']['school_year'] symbol = data['data']['symbol'] received_messages = get_received_messages(register_id, register_r, oun, s, date, school_year, symbol) - return JsonResponse(received_messages, safe=False) + return JsonResponse(received_messages) else: return redirect('../') @@ -176,7 +177,7 @@ def sent_messages(request, *args, **kwargs): school_year = data['data']['school_year'] symbol = data['data']['symbol'] sent_messages = get_sent_messages(register_id, register_r, oun, s, date, school_year, symbol) - return JsonResponse(sent_messages, safe=False) + return JsonResponse(sent_messages) else: return redirect('../') @@ -191,6 +192,18 @@ def deleted_messages(request, *args, **kwargs): school_year = data['data']['school_year'] symbol = data['data']['symbol'] deleted_messages = get_deleted_messages(register_id, register_r, oun, s, date, school_year, symbol) - return JsonResponse(deleted_messages, safe=False) + return JsonResponse(deleted_messages) + else: + return redirect('../') + +def school_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'] + school_data = get_school_data(register_id, register_r, oun, s) + return JsonResponse(school_data) else: return redirect('../') \ No newline at end of file diff --git a/files/js/login.js b/files/js/login.js index e3bad76..61a0176 100644 --- a/files/js/login.js +++ b/files/js/login.js @@ -33,7 +33,8 @@ const login = () => { if(data['success']){ myStorage = window.sessionStorage; sessionStorage.setItem('cookies_data', JSON.stringify(data)); - sessionStorage.setItem('csrfcookie', csrfcookie()) + sessionStorage.setItem('csrfcookie', csrfcookie()); + sessionStorage.setItem('email', document.querySelector('#id_loginName').value); window.location.href = "/content/"; } else{ diff --git a/files/js/school_data.js b/files/js/school_data.js new file mode 100644 index 0000000..fab7644 --- /dev/null +++ b/files/js/school_data.js @@ -0,0 +1,22 @@ +const school_data = document.querySelector('#school_data_'); + +myStorage = window.sessionStorage; + +const getSchoolData = () => { + document.querySelector('#content').innerHTML = 'Here is school data (in my imagination)'; + cookies_data = sessionStorage.getItem('cookies_data'); + csrfcookie_ = sessionStorage.getItem('csrfcookie'); + fetch(url = '../api/school_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); + }) +} + +school_data_.addEventListener('click', getSchoolData); \ No newline at end of file diff --git a/files/js/start.js b/files/js/start.js index 050732a..f15e119 100644 --- a/files/js/start.js +++ b/files/js/start.js @@ -1,22 +1,16 @@ -function grade_action(id) { - var x = document.getElementById(id); - var element = x.getElementsByTagName('li')[0]; - if(element.style.display == 'none'){ - element.style.display = 'block'; - } - else if(element.style.display == 'block'){ - element.style.display = 'none'; - } -} +const name_ = document.querySelector('#name'); +const email_ = document.querySelector('#email'); -function change_message_content(id) { - $.ajax({ - url: '/change_messages_content/', - data: { - 'id': id - }, - success: function(data) { - document.querySelector('#messages_content').innerHTML = data; - } - }); -} \ No newline at end of file +myStorage = window.sessionStorage; + +const studentName = () => { + const cookies_data = JSON.parse(sessionStorage.getItem('cookies_data')) + name_.innerHTML = cookies_data['data']['register_r']['data'][0]['UczenImie']+' '+cookies_data['data']['register_r']['data'][0]['UczenImie2']+' '+cookies_data['data']['register_r']['data'][0]['UczenNazwisko'] +}; + +const studentEmail = () => { + email_.innerHTML = sessionStorage.getItem('email') +}; + +window.addEventListener('load', studentName); +window.addEventListener('load', studentEmail); \ No newline at end of file diff --git a/templates/content.html b/templates/content.html index b50a436..91e98b4 100644 --- a/templates/content.html +++ b/templates/content.html @@ -6,8 +6,8 @@ - - + + @@ -15,6 +15,7 @@ + @@ -41,8 +42,8 @@ - John Doe - jdandturk@gmail.com + John Doe + jdandturk@gmail.com
  • filter_6Oceny
  • event_notePlan Lekcji
  • @@ -51,6 +52,7 @@
  • date_rangeFrekwencja
  • emoji_eventsUwagi i Osiągnięcia
  • devicesDostęp Mobilny
  • +
  • businessSzkoła i Nauczyciele
  • emailWiadomości