murphyslemon / Raspberry_Pi_Server

International Sensor Development Project: This project is a voting system that uses a raspberry pi server and multiple voting devices. The system is easy, secure, scalable, and supports anonymous and registered voting. This repository focuses on the Raspberry Pi server.
0 stars 3 forks source link

create_user function #6

Open MagnusLii opened 10 months ago

MagnusLii commented 10 months ago

User and ESP Data Registration Function

Goal

The objective is to create a function that, upon prompt from the website, processes a JSON string containing ESP ID and optionally Username. This function transforms the JSON string into an SQL query and sends it to the database for execution.

Arguments

Returns

Function Name: create_user

MagnusLii commented 9 months ago

Instead of a json containing the userID and espID the function takes in each of these as separate arguments.

def create_user(username, deviceID):
    try:
        user = Users(Username=username, DeviceIndex=deviceID)
        db.session.add(user)
        db.session.commit()

        return True, "User created successfully."

    except Exception as errorMsg:
        return False, str(errorMsg)