diff options
author | Saptak S <saptak013@gmail.com> | 2020-05-11 12:51:46 +0530 |
---|---|---|
committer | Saptak S <saptak013@gmail.com> | 2020-05-11 12:51:46 +0530 |
commit | afc6a2f4ce3b6d35060947f4264ccd8369acf544 (patch) | |
tree | 511992a9134c72c49218693bbc4d6933452daa71 /onionshare | |
parent | 409f3f7fbe714ae3a4d390671f199b647ad8ac61 (diff) | |
download | onionshare-afc6a2f4ce3b6d35060947f4264ccd8369acf544.tar.gz onionshare-afc6a2f4ce3b6d35060947f4264ccd8369acf544.zip |
Update username via both socket and ajax
- socket takes care of modifying the username in the forked socket
session and sending a status message to chat window
- ajax request takes care of updating the flask session so that on
refresh or re-opening of the URL in same browser, the username remains
same
Diffstat (limited to 'onionshare')
-rw-r--r-- | onionshare/web/chat_mode.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/onionshare/web/chat_mode.py b/onionshare/web/chat_mode.py index ed946a14..965a234c 100644 --- a/onionshare/web/chat_mode.py +++ b/onionshare/web/chat_mode.py @@ -3,6 +3,7 @@ from flask import ( request, render_template, make_response, + jsonify, flash, redirect, session, @@ -59,6 +60,24 @@ class ChatModeWeb: ) return self.web.add_security_headers(r) + @self.web.app.route("/update-session-username", methods=["POST"]) + def update_session_username(): + history_id = self.cur_history_id + data = request.get_json() + session["name"] = data.get("username", session.get("name")) + self.web.add_request( + request.path, {"id": history_id, "status_code": 200}, + ) + + self.web.add_request(self.web.REQUEST_LOAD, request.path) + r = make_response( + jsonify( + username=session.get("name"), + success=True, + ) + ) + return self.web.add_security_headers(r) + @self.web.socketio.on("joined", namespace="/chat") def joined(message): """Sent by clients when they enter a room. |