Merge pull request #11 from wulkanowy/feature/get_message_content

Getting message content
This commit is contained in:
Pengwius 2021-01-21 13:00:40 +01:00 committed by GitHub
commit 23cbd6ad90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 3 deletions

View file

@ -155,4 +155,45 @@ def send_message(register_id, register_r, oun, s, date, school_year, symbol, sen
send = sess.post(f'{link}/NowaWiadomosc.mvc/InsertWiadomosc', data=json.dumps(payload))
return send.json()
return send.json()
def get_message_content(register_id, register_r, oun, s, date, school_year, symbol, message_id):
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Accept': '*/*',
'Connection': 'keep-alive',
"User-Agent": "Wulkanowy-web :)"
}
if oun == 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
link = f'http://uonetplus-uzytkownik.fakelog.cf/{symbol}'
else:
link = f'https://uonetplus-uzytkownik.vulcan.net.pl/{symbol}'
sess = requests.Session()
sess.cookies.update(s)
sess.headers.update(headers)
index = sess.get(link)
antiForgeryToken = re.search("antiForgeryToken: '(.)*'", index.text)
antiForgeryToken = antiForgeryToken.group()
antiForgeryToken = antiForgeryToken.replace('antiForgeryToken: ', '').replace("'", "")
appGuid = re.search("appGuid: '(.)*'", index.text)
appGuid = appGuid.group()
appGuid = appGuid.replace('appGuid: ', '').replace("'", "")
sess.headers.update({
'X-V-RequestVerificationToken': antiForgeryToken,
'X-V-AppGuid': appGuid
})
payload = {
'messageId': message_id
}
content = sess.post(f'{link}/Wiadomosc.mvc/GetInboxMessageDetails', data=json.dumps(payload))
return content.json()

View file

@ -14,7 +14,7 @@ from .API.exams import get_exams
from .API.timetable import get_timetable
from .API.notes import get_notes
from .API.attendance import get_attendance
from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients, send_message
from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients, send_message, get_message_content
from .API.homeworks import get_homeworks
from .API.mobile_access import get_registered_devices, register_device
from .API.school_data import get_school_data
@ -293,5 +293,24 @@ def send(request, *args, **kwargs):
send_data = {'data': data['data'], 'subject': data['subject'], 'content': data['content']}
send = send_message(register_id, register_r, oun, s, date, school_year, symbol, send_data)
return JsonResponse(send, safe=False)
else:
return redirect('../')
def message_content(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
cookies_data = json.loads(data['cookies_data'])
register_id = cookies_data['data']['register_id']
register_r = cookies_data['data']['register_r']
oun = cookies_data['data']['oun']
s = cookies_data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
date = cookies_data['data']['date']
school_year = cookies_data['data']['school_year']
symbol = cookies_data['data']['symbol']
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('../')

View file

@ -52,6 +52,8 @@ const getReceivedMessages = () => {
dataWyslania = wiadomoscRow.insertCell()
dataWyslania.innerHTML = `<span>${wiadomosc.Data}</span>`
wiadomoscRow.appendChild(dataWyslania)
document.getElementById(wiadomosc.Id).addEventListener('click', getMessageContent);
})
})
}
@ -103,6 +105,8 @@ const getSentMessages = () => {
dataWyslania = wiadomoscRow.insertCell()
dataWyslania.innerHTML = `<span>${wiadomosc.Data}</span>`
wiadomoscRow.appendChild(dataWyslania)
document.getElementById(wiadomosc.Id).addEventListener('click', getMessageContent);
})
})
}
@ -154,6 +158,8 @@ const getDeletedMessages = () => {
dataWyslania = wiadomoscRow.insertCell()
dataWyslania.innerHTML = `<span>${wiadomosc.Data}</span>`
wiadomoscRow.appendChild(dataWyslania)
document.getElementById(wiadomosc.Id).addEventListener('click', getMessageContent);
})
})
}
@ -224,6 +230,24 @@ const sendMessage = () => {
}
const getMessageContent = (event) => {
send_data = {
'cookies_data': cookies_data,
'message_id': event.target.id
}
fetch(url = '../api/messages/content', {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfcookie_
},
body: JSON.stringify(send_data)
}).then(response => response.json()).then(data => {
console.log(data)
})
}
received_.addEventListener('click', getReceivedMessages);
sent_.addEventListener('click', getSentMessages);

View file

@ -17,7 +17,7 @@ from django.urls import path
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from app.views import default_view, content_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
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
urlpatterns = [
#views
@ -42,6 +42,7 @@ urlpatterns = [
path('api/messages/deleted', deleted_messages, name='deleted_messages'),
path('api/messages/recipients', recipients, name='recipients'),
path('api/messages/send', send, name='send_message'),
path('api/messages/content', message_content, name='message_content'),
]
urlpatterns += staticfiles_urlpatterns()