Ejemplo n.º 1
0
def send_content():
    global http_headers
    global template
    global body
    global head
    template = template.replace("<!--signout-->", (
        '<a class="mdl-navigation__link" href="signout.py"><i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">power_settings_new</i>Sign Out</a>'
        if session.is_signed_in() else ""))
    print(http_headers)
    print(
        template.replace("<!--Head_Content-->",
                         head).replace("<!--Body_Content-->", body))
Ejemplo n.º 2
0
#!/usr/bin/python3
from helpers import form
from helpers import session
from helpers import cookies
import json
import hashlib
import datetime
import cgitb

print("Content-Type: text/html")

if session.is_signed_in():
    print("")
    print("You are already signed in as " + session.get_user_id() +
          " ! Redirecting you back in 5 seconds...")
    print('<meta http-equiv="refresh" content="5; url=./profile.py">')
    exit()

users = json.loads(open("users.json").read())

if form.form("username") in users and users[form.form(
        "username")]["password"] == str(
            hashlib.sha256(form.form("password").encode("utf-8")).hexdigest()):
    expires = datetime.datetime.now()
    expires = expires + datetime.timedelta(hours=24)
    expires_string = expires.strftime("%Y,%m,%d,%H,%M,%S")

    existing_sessions = json.loads(open("sessions.json").read())

    session_token = cookies.random_str(32)
Ejemplo n.º 3
0
#!/usr/bin/python3
from helpers import form
from helpers import session
import json

print("Content-Type: text/html\n")

if not session.is_signed_in():
    print("You are not signed in! Redirecting you back in 5 seconds...")
    print('<meta http-equiv="refresh" content="5; url=./profile.py">')
    exit()

users = json.loads(open("users.json").read())

if form.form("email") is not None:
    users[session.get_user_id()]["email_address"] = form.form("email")

if form.form("preferred_name") is not None:
    users[session.get_user_id()]["preferred_name"] = form.form(
        "preferred_name")

# Save the data
open("users.json", "w").write(json.dumps(users))

print("Your updates have been stored! Redirecting you back in 5 seconds...")
print('<meta http-equiv="refresh" content="5; url=./profile.py">')