Пример #1
0
            qrdata = "{ \"token\": \"" + token + "\", \"society_id\": \"" + society_id + "\"}"

            # Generate qr code
            qr = QRCode(version=None,
                        box_size=10,
                        error_correction=ERROR_CORRECT_L)
            qr.add_data(qrdata)
            qr.make(fit=True)

            im = qr.make_image()
            im.save("/var/www/html/img/" + token + ".png")

            # Store the token in the database
            sql = "INSERT INTO join_token VALUES(" + society_id + ", '" + token + "', NULL)"
            db.cur.execute(sql)

            response = api.set_returncode(0)
            api.update_response("token", token)
        else:
            response = api.set_returncode(7)
    else:
        response = api.set_returncode(1)
else:
    response = api.set_returncode(5)

# Send response
api.send_response()

# Close db connection
db.close()
Пример #2
0
import database
import api

db = database.Database()
api = api.Api("json")

# Ensure the correct post keys were sent
if api.check_keys(("member_id", "session_id")):
    member_id = api.request["member_id"].value
    session_id = api.request["session_id"].value

    if db.check_session(member_id, session_id):
        sql = "SELECT society_id FROM member_society WHERE(member_id = " + member_id + ");"
        db.cur.execute(sql)
        result = db.cur.fetchall()
        list_of_socs = []
        for row in result:
            list_of_socs.append(str(row[0]))
        response = api.set_returncode(0)
        api.update_response("society_id", list_of_socs)
    else:
        response = api.set_returncode(1)
else:
    response = api.set_returncode(5)

# Send response
api.send_response()

# Close db connection
db.close()
Пример #3
0
        try:
            db.cur.execute(sql)
            result = db.cur.fetchall()

            soc_arr = []
            for row in result:
                soc_details = {}
                soc_details["society_id"] = row[0]
                soc_details["name"] = row[1]
                soc_details["email"] = row[2]
                soc_details["description"] = row[3]

                soc_arr.append(soc_details)

            api.set_returncode(0)
            api.update_response("society_details", soc_arr)
        except:
            api.set_returncode(6)

    else:
        api.set_returncode(1)
else:
    api.set_returncode(5)

# Send response
api.send_response()

# Close db connection
db.close()
Пример #4
0
                # Clear any old session IDs before generating a new one
                member_id = row[3]
                sql = "DELETE FROM session WHERE(member_id = " + str(
                    member_id) + ");"
                db.cur.execute(sql)

                # Generate random session ID for user
                session_id = str(uuid.uuid4().hex)

                # Store session ID for that user in the database
                sql = "INSERT INTO session VALUES(" + str(
                    member_id) + ",'" + str(session_id) + "');"
                db.cur.execute(sql)

                response = api.set_returncode(0)
                api.update_response("session_id", session_id)
                api.update_response("member_id", member_id)
            else:
                response = api.set_returncode(2)
    else:
        response = api.set_returncode(2)
else:
    response = api.set_returncode(5)

# Send response
api.send_response()

# Close db connection
db.close()
Пример #5
0
                    # Insert the user into the database
                    sql = "INSERT INTO member_society(member_id, society_id) VALUES(" + member_id + ", " + society_id + ");"
                    db.cur.execute(sql)
                    # Remove the qr code and database entry for the token
                    path = "/var/www/html/img/" + token + ".png"
                    subprocess.call(["rm", path])
                    sql = "DELETE FROM join_token WHERE(token = '" + token + "')"
                    db.cur.execute(sql)
                    response = api.set_returncode(0)
                else:
                    # Invalid join token
                    response = api.set_returncode(8)
            except Exception as e:
                # Database error
                response = api.set_returncode(6)
                api.update_response("dberror", str(e))
        else:
            response = api.set_returncode(9)
    else:
        # Invalid session id
        response = api.set_returncode(1)
else:
    # Invalid post request
    response = api.set_returncode(5)

# Send response
api.send_response()

# Close db connection
db.close()
Пример #6
0
db = database.Database()
api = api.Api("json")

# Ensure the correct post keys were sent
if api.check_keys(("member_id", "session_id")):
    member_id = api.request["member_id"].value
    session_id = api.request["session_id"].value

    # Ensure the user's session is valid
    if db.check_session(member_id, session_id):
        sql = "SELECT member_id, name, email, dob, mobile, emergency_ph, full_part_time FROM member WHERE(member_id = " + member_id + ");"
        db.cur.execute(sql)
        row = db.cur.fetchone()

        # Add user's details to response
        api.update_response("member_id", row[0])
        api.update_response("name", row[1])
        api.update_response("email", row[2])
        api.update_response("dob", str(row[3]))
        api.update_response("mobile", row[4])
        api.update_response("emergency_ph", row[5])
        api.update_response("full_part_time", row[6])

        response = api.set_returncode(0)
    else:
        response = api.set_returncode(1)
else:
    response = api.set_returncode(5)

# Send response
api.send_response()