def signout(self): """Logs the current user out, expires their session""" username = cherrypy.session.get('username') serverFunctions.report(pubkey_hex_str, headers, "offline") if username == None: pass else: cherrypy.lib.sessions.expire() username = None raise cherrypy.HTTPRedirect('/')
def dashboard(self): print("username + password " + username + password) serverFunctions.ping(pubkey_hex_str, signing_key, headers) print("refresh pinged") serverFunctions.report(pubkey_hex_str, headers, "online") print("refresh report") template = env.get_template('dashboard.html') broadcasts = database.get_all_broadcasts() return template.render(onlineusers=getUsers(), username=username, recentbroadcasts=broadcasts)
def privateMessage(self, error="0"): global current_onlineusers current_onlineusers = clientFunctions.get_onlineusernames(headers) serverFunctions.ping(pubkey_hex_str, signing_key, headers) serverFunctions.report(pubkey_hex_str, headers, "online") template = env.get_template('privatemessage.html') return template.render(onlineusers=current_onlineusers, pastmessages="", error=error)
def authoriseUserLogin(username_given=None, password_given=None): print("Log on attempt from {0}:{1}".format(username_given, password_given)) credentials = ('%s:%s' % (username_given, password_given)) b64_credentials = base64.b64encode(credentials.encode('ascii')) test_headers = { 'Authorization': 'Basic %s' % b64_credentials.decode('ascii'), 'Content-Type': 'application/json; charset=utf-8', } response = serverFunctions.ping(None, signing_key, test_headers) print(response) if response["authentication"] == 'basic' or response[ "authentication"] == 'api-key': global username global password username = username_given password = password_given global signing_key signing_key = nacl.signing.SigningKey.generate() global pubkey pubkey = signing_key.verify_key.encode( encoder=nacl.encoding.HexEncoder) global pubkey_hex_str pubkey_hex_str = pubkey.decode('utf-8') global headers headers = test_headers serverFunctions.add_pubkey(pubkey_hex_str, signing_key, username, headers) serverFunctions.ping(pubkey_hex_str, signing_key, headers) serverFunctions.report(pubkey_hex_str, headers, "online") serverFunctions.get_loginserver_record(headers) clientFunctions.ping_all_online(headers) print(pubkey_hex_str) #serverFunctions.add_privatedata("Hello",headers,signing_key, "1234") #serverFunctions.get_privatedata(headers,signing_key) print("Success") return 0 else: print("Failure") return 1
def changeMessagePage(self, sender_username=None, error="0"): print("refreshed ping in change pm") serverFunctions.ping(pubkey_hex_str, signing_key, headers) print("refreshed reprt in change pm") serverFunctions.report(pubkey_hex_str, headers, "online") global current_selected_user current_selected_user = sender_username template = env.get_template('privatemessage.html') if sender_username != None: print(sender_username) past_messages_database = database.get_messages_from( username, sender_username) return template.render(onlineusers=current_onlineusers, pastmessages=past_messages_database, currentuser=sender_username, error=error) else: return template.render( onlineusers=clientFunctions.get_onlineusernames(headers), pastmessages="", error=error)