33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import mysql.connector
|
|
import os
|
|
import json
|
|
import bcrypt
|
|
|
|
config_path = '../src/server/BreCal/connection_data.json'
|
|
print (os.getcwd())
|
|
if not os.path.exists(config_path):
|
|
print ('cannot find ' + config_path)
|
|
exit(1)
|
|
|
|
f = open(config_path);
|
|
connection_data = json.load(f)
|
|
mydb = mysql.connector.connect(host=connection_data["host"], user=connection_data["user"],
|
|
password = connection_data["password"], database=connection_data["database"])
|
|
print(mydb)
|
|
|
|
# insert a new user
|
|
participant_id = 1
|
|
first_name = "Londo"
|
|
last_name = "Mollari"
|
|
user_name = "Londo"
|
|
user_email = "l.mollari@centauri.gov"
|
|
user_phone = "+01 555 324 2313"
|
|
password = "Hallowach"
|
|
password_hash = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt( 12 )).decode('utf8')
|
|
|
|
query = "INSERT INTO user (participant_id, first_name, last_name, user_name, user_email, user_phone, password_hash) VALUES (" + str(participant_id) + ",\"" + first_name + "\",\"" + last_name + "\",\"" + user_name + "\",\"" + user_email + "\",\"" + user_phone + "\",\"" + password_hash + "\")"
|
|
with mydb.cursor() as cursor:
|
|
cursor.execute(query)
|
|
mydb.commit()
|
|
|