Sending message
This commit is contained in:
parent
fa08d6d8eb
commit
c654711b4a
7 changed files with 178 additions and 9 deletions
|
@ -2,6 +2,7 @@ import requests
|
||||||
import json
|
import json
|
||||||
import calendar
|
import calendar
|
||||||
import time
|
import time
|
||||||
|
import re
|
||||||
|
|
||||||
def get_received_messages(register_id, register_r, oun, s, date, school_year, symbol):
|
def get_received_messages(register_id, register_r, oun, s, date, school_year, symbol):
|
||||||
headers = {
|
headers = {
|
||||||
|
@ -74,4 +75,84 @@ def get_recipients(register_id, register_r, oun, s, date, school_year, symbol):
|
||||||
}
|
}
|
||||||
get_addressee = requests.post(f'{link}/Adresaci.mvc/GetAddressee', headers=headers, cookies=s, json=data)
|
get_addressee = requests.post(f'{link}/Adresaci.mvc/GetAddressee', headers=headers, cookies=s, json=data)
|
||||||
|
|
||||||
return get_addressee.json()
|
return {'addressee': get_addressee.json(), 'unitId': id_jednostka}
|
||||||
|
|
||||||
|
def send_message(register_id, register_r, oun, s, date, school_year, symbol, send_data):
|
||||||
|
headers = {
|
||||||
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
|
'Accet': '*/*',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
"User-Agent": "Wulkanowy-web :)",
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'TE': "Trailers"
|
||||||
|
}
|
||||||
|
|
||||||
|
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}'
|
||||||
|
|
||||||
|
student_data = register_r['data'][0]['UczenNazwisko']+' '+register_r['data'][0]['UczenImie']
|
||||||
|
|
||||||
|
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 = {
|
||||||
|
"incomming": {
|
||||||
|
"Id": 0,
|
||||||
|
"Nieprzeczytane": 0,
|
||||||
|
"Przeczytane": 0,
|
||||||
|
"Nieprzeczytana": False,
|
||||||
|
"FolderWiadomosci": 0,
|
||||||
|
"WiadomoscPowitalna": False,
|
||||||
|
"Data": None,
|
||||||
|
"Tresc": send_data['content'],
|
||||||
|
"Temat": send_data['subject'],
|
||||||
|
"IdWiadomosci": 0,
|
||||||
|
"HasZalaczniki": False,
|
||||||
|
"Zalaczniki": "",
|
||||||
|
"Adresaci": [
|
||||||
|
{
|
||||||
|
"Id": send_data['data']['Id'],
|
||||||
|
"IdReceiver": "",
|
||||||
|
"Name": send_data['data']['Name'],
|
||||||
|
"Role": send_data['data']['Role'],
|
||||||
|
"UnitId": send_data['data']['UnitId'],
|
||||||
|
"IdLogin": send_data['data']['IdLogin'],
|
||||||
|
"PushWiadomosc": False,
|
||||||
|
"Hash": send_data['data']['Hash'],
|
||||||
|
"Date": None,
|
||||||
|
"IsMarked": False
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"WyslijJako": student_data,
|
||||||
|
"WiadomoscAdresatLogin": "",
|
||||||
|
"IdWiadomoscAdresatLogin": None,
|
||||||
|
"RolaNadawcy": 0,
|
||||||
|
"NieprzeczytanePrzeczytane": "0/0",
|
||||||
|
"NadawcaNazwa": "Brak nadawcy",
|
||||||
|
"IdNadawca": 0,
|
||||||
|
"AdresaciNazwa": "Brak adresata"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
send = sess.post(f'{link}/NowaWiadomosc.mvc/InsertWiadomosc', data=json.dumps(payload))
|
||||||
|
|
||||||
|
return send.json()
|
19
app/views.py
19
app/views.py
|
@ -12,7 +12,7 @@ from .API.exams import get_exams
|
||||||
from .API.timetable import get_timetable
|
from .API.timetable import get_timetable
|
||||||
from .API.notes import get_notes
|
from .API.notes import get_notes
|
||||||
from .API.attendance import get_attendance
|
from .API.attendance import get_attendance
|
||||||
from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients
|
from .API.messages import get_received_messages, get_sent_messages, get_deleted_messages, get_recipients, send_message
|
||||||
from .API.homeworks import get_homeworks
|
from .API.homeworks import get_homeworks
|
||||||
from .API.mobile_access import get_registered_devices, register_device
|
from .API.mobile_access import get_registered_devices, register_device
|
||||||
from .API.school_data import get_school_data
|
from .API.school_data import get_school_data
|
||||||
|
@ -236,3 +236,20 @@ def dashboard(request, *args, **kwargs):
|
||||||
return JsonResponse(dashboard)
|
return JsonResponse(dashboard)
|
||||||
else:
|
else:
|
||||||
return redirect('../')
|
return redirect('../')
|
||||||
|
|
||||||
|
def send(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']
|
||||||
|
date = cookies_data['data']['date']
|
||||||
|
school_year = cookies_data['data']['school_year']
|
||||||
|
symbol = cookies_data['data']['symbol']
|
||||||
|
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('../')
|
||||||
|
|
|
@ -3,6 +3,7 @@ const sent_ = document.querySelector('#sent_');
|
||||||
const deleted_ = document.querySelector('#deleted_');
|
const deleted_ = document.querySelector('#deleted_');
|
||||||
const content = document.getElementById("content");
|
const content = document.getElementById("content");
|
||||||
const send_ = document.querySelector('#send_')
|
const send_ = document.querySelector('#send_')
|
||||||
|
var hash = require('object-hash');
|
||||||
|
|
||||||
const getReceivedMessages = () => {
|
const getReceivedMessages = () => {
|
||||||
content.innerHTML = ""
|
content.innerHTML = ""
|
||||||
|
@ -157,7 +158,7 @@ const getDeletedMessages = () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const sendMessage = () => {
|
const getAddressee = () => {
|
||||||
cookies_data = sessionStorage.getItem('cookies_data');
|
cookies_data = sessionStorage.getItem('cookies_data');
|
||||||
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
||||||
fetch(url = '../api/messages/recipients', {
|
fetch(url = '../api/messages/recipients', {
|
||||||
|
@ -170,11 +171,61 @@ const sendMessage = () => {
|
||||||
body: cookies_data
|
body: cookies_data
|
||||||
}).then(response => response.json()).then(data => {
|
}).then(response => response.json()).then(data => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
document.querySelector('#content').innerHTML = `
|
||||||
|
<form action="javascript:void(0);">
|
||||||
|
<div class="input-field">
|
||||||
|
<select id='recipients' style='display: inline !important;'>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="input-field">
|
||||||
|
<input required="" placeholder="Temat" id="subject" class="input-field">
|
||||||
|
</div>
|
||||||
|
<div class="input-field">
|
||||||
|
<input required="" placeholder="Treść" id="message-content" class="input-field">
|
||||||
|
</div>
|
||||||
|
<button id="button" class="waves-light waves-effect btn red darken-1">WYŚLIJ</button>
|
||||||
|
</form>`
|
||||||
|
data.addressee.data.forEach((recipient) => {
|
||||||
|
const recipient_hash = `${hash.MD5(recipient)}`
|
||||||
|
document.querySelector('#recipients').insertAdjacentHTML('beforeend', '<option value="'+recipient_hash+'">'+recipient.Name+'</option>');
|
||||||
|
sessionStorage.setItem(recipient_hash, JSON.stringify(recipient));
|
||||||
|
const button_ = document.querySelector('#button');
|
||||||
|
button_.addEventListener('click', sendMessage);
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const sendMessage = () => {
|
||||||
|
const recipient_hash_ = document.querySelector('#recipients').value;
|
||||||
|
const subject_ = document.querySelector('#subject').value;
|
||||||
|
const content_ = document.querySelector('#message-content').value;
|
||||||
|
const recipient_ = JSON.parse(sessionStorage.getItem(recipient_hash_));
|
||||||
|
if(subject_ != '' && content_ != ''){
|
||||||
|
cookies_data = sessionStorage.getItem('cookies_data');
|
||||||
|
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
||||||
|
send_data = {
|
||||||
|
'cookies_data': cookies_data,
|
||||||
|
'data': recipient_,
|
||||||
|
'subject': subject_,
|
||||||
|
'content': content_
|
||||||
|
}
|
||||||
|
fetch(url = '../api/messages/send', {
|
||||||
|
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);
|
received_.addEventListener('click', getReceivedMessages);
|
||||||
sent_.addEventListener('click', getSentMessages);
|
sent_.addEventListener('click', getSentMessages);
|
||||||
deleted_.addEventListener('click', getDeletedMessages);
|
deleted_.addEventListener('click', getDeletedMessages);
|
||||||
send_.addEventListener('click', sendMessage);
|
send_.addEventListener('click', getAddressee);
|
19
package-lock.json
generated
19
package-lock.json
generated
|
@ -1939,6 +1939,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"md5-jkmyers": {
|
||||||
|
"version": "0.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/md5-jkmyers/-/md5-jkmyers-0.0.1.tgz",
|
||||||
|
"integrity": "sha1-t9PfKAe5HV7H8zc7V/JNYLD6krs="
|
||||||
|
},
|
||||||
"merge-stream": {
|
"merge-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||||
|
@ -2198,6 +2203,15 @@
|
||||||
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
|
"integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"reverse-md5": {
|
||||||
|
"version": "0.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/reverse-md5/-/reverse-md5-0.0.5.tgz",
|
||||||
|
"integrity": "sha512-nSzYU/we3UHObW0rHdf/680AxlAuaVH9fmV3l/1/fnyzbphPPpTFZ684g4wQ2Ru+2lCOdmu8rgWJTTmg/JoXfA==",
|
||||||
|
"requires": {
|
||||||
|
"md5-jkmyers": "^0.0.1",
|
||||||
|
"xtend": "^4.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.2.1",
|
"version": "5.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||||
|
@ -2480,6 +2494,11 @@
|
||||||
"isexe": "^2.0.0"
|
"isexe": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"xtend": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="
|
||||||
|
},
|
||||||
"yocto-queue": {
|
"yocto-queue": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/wulkanowy/wulkanowy-web#readme",
|
"homepage": "https://github.com/wulkanowy/wulkanowy-web#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"object-hash": "^2.1.1"
|
"object-hash": "^2.1.1",
|
||||||
|
"reverse-md5": "0.0.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.12.10",
|
"@babel/core": "^7.12.10",
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<script src="{% static 'js/notes.js' %}" type="text/javascript" defer></script>
|
<script src="{% static 'js/notes.js' %}" type="text/javascript" defer></script>
|
||||||
<script src="{% static 'js/attendance.js' %}" type="text/javascript" defer></script>
|
<script src="{% static 'js/attendance.js' %}" type="text/javascript" defer></script>
|
||||||
<script src="{% static 'js/homeworks.js' %}" type="text/javascript" defer></script>
|
<script src="{% static 'js/homeworks.js' %}" type="text/javascript" defer></script>
|
||||||
<script src="{% static 'js/messages.js' %}" type="text/javascript" defer></script>
|
<script src="{% static 'js/dist/out-messages.js' %}" type="text/javascript" defer></script>
|
||||||
<script src="{% static 'js/mobile_access.js' %}" type="text/javascript" defer></script>
|
<script src="{% static 'js/mobile_access.js' %}" type="text/javascript" defer></script>
|
||||||
<script src="{% static 'js/school_data.js' %}" type="text/javascript" defer></script>
|
<script src="{% static 'js/school_data.js' %}" type="text/javascript" defer></script>
|
||||||
<link rel="shortcut icon" href="{% static 'images/27146352.png' %}">
|
<link rel="shortcut icon" href="{% static 'images/27146352.png' %}">
|
||||||
|
@ -66,7 +66,6 @@
|
||||||
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
|
<a href="#" data-target="slide-out" class="sidenav-trigger"><i class="material-icons">menu</i></a>
|
||||||
|
|
||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
|
|
@ -17,7 +17,7 @@ from django.urls import path
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
|
|
||||||
from app.views import default_view, content_view
|
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
|
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
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
#views
|
#views
|
||||||
|
@ -41,6 +41,7 @@ urlpatterns = [
|
||||||
path('api/messages/sent', sent_messages, name='sent_messages'),
|
path('api/messages/sent', sent_messages, name='sent_messages'),
|
||||||
path('api/messages/deleted', deleted_messages, name='deleted_messages'),
|
path('api/messages/deleted', deleted_messages, name='deleted_messages'),
|
||||||
path('api/messages/recipients', recipients, name='recipients'),
|
path('api/messages/recipients', recipients, name='recipients'),
|
||||||
|
path('api/messages/send', send, name='send_message'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += staticfiles_urlpatterns()
|
urlpatterns += staticfiles_urlpatterns()
|
Loading…
Reference in a new issue