Example #1
0
def addkey():
    # Read in the key data from the form.
    try:
        keydata = request.args.get("keydata")
    except KeyError:
        return json.dumps({"error": 1, "msg": "no-key"}), 401, {"Content-Type": "application/json"}
    # Attempt to add the key.
    key = pgp.add_pgp_key(keydata)
    if key[0]:
        pgpactions.broadcast_add(key[2])
        return json.dumps({"error": 0, "msg": key[1]}), 200, {"Content-Type": "application/json"}
    else:
        return json.dumps({"error": key[1], "msg": "invalid-key-data"}), 401, {"Content-Type": "application/json"}
Example #2
0
def add():
    # Get the key from the form
    key = request.form.get("enterkey")
    if not key:
        return render_template("submit.html")
    else:
        # Import the key
        imported = pgp.add_pgp_key(key)
        if not imported[0]:
            if imported[1] == -1:
                return render_template("submit.html", success=False, errormsg="Seems like an error happened importing your key. Double-check you copy/pasted it correctly.")
            elif imported[1] == -2:
                return render_template("submit.html", success=False, errormsg="Your key is already added on the server and is unchanged.")
            elif imported[1] == -3:
                return render_template("submit.html", success=False, errormsg="Your key was invalid and could not be imported.")
        else:
            keyinfo = pgp.get_pgp_keyinfo(imported[1])
            broadcast_add(imported[2])
            return redirect(url_for("frontend.getkeyinfo", key=keyinfo.shortid, added=True)), 302