Added exception handling
This commit is contained in:
		@@ -1,15 +1,22 @@
 | 
				
			|||||||
import mariadb
 | 
					import mariadb
 | 
				
			||||||
 | 
					import traceback
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_master_pass(
 | 
					def add_master_pass(
 | 
				
			||||||
    id: int, hashed_passwd: bytes, salt: bytes, con: mariadb.Connection
 | 
					    id: int, hashed_passwd: bytes, salt: bytes, con: mariadb.Connection
 | 
				
			||||||
) -> bool:
 | 
					) -> bool:
 | 
				
			||||||
    cursor = con.cursor()
 | 
					    cursor = con.cursor()
 | 
				
			||||||
    cursor.execute(
 | 
					    try:
 | 
				
			||||||
        "INSERT INTO master_pass (user_id, salt, passwd) VALUES (?, ?, ?)",
 | 
					        cursor.execute(
 | 
				
			||||||
        [id, hashed_passwd, salt],
 | 
					            "INSERT INTO master_pass (user_id, salt, passwd) VALUES (?, ?, ?)",
 | 
				
			||||||
    )
 | 
					            [id, hashed_passwd, salt],
 | 
				
			||||||
    cursor.close()
 | 
					        )
 | 
				
			||||||
 | 
					        cursor.close()
 | 
				
			||||||
 | 
					    except Exception:
 | 
				
			||||||
 | 
					        traceback.print_exc()
 | 
				
			||||||
 | 
					        return False
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        return True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_account(
 | 
					def add_account(
 | 
				
			||||||
@@ -21,8 +28,14 @@ def add_account(
 | 
				
			|||||||
    con: mariadb.Connection,
 | 
					    con: mariadb.Connection,
 | 
				
			||||||
) -> bool:
 | 
					) -> bool:
 | 
				
			||||||
    cursor = con.cursor()
 | 
					    cursor = con.cursor()
 | 
				
			||||||
    cursor.execute(
 | 
					    try:
 | 
				
			||||||
        "INSERT INTO accounts (user_id, acc_name, salt, enc_login, enc_pass) VALUES (?, ?, ?, ?, ?, ?)",
 | 
					        cursor.execute(
 | 
				
			||||||
        [id, acc_name, salt, enc_login, enc_passwd],
 | 
					            "INSERT INTO accounts (user_id, acc_name, salt, enc_login, enc_pass) VALUES (?, ?, ?, ?, ?, ?)",
 | 
				
			||||||
    )
 | 
					            [id, acc_name, salt, enc_login, enc_passwd],
 | 
				
			||||||
    cursor.close()
 | 
					        )
 | 
				
			||||||
 | 
					        cursor.close()
 | 
				
			||||||
 | 
					    except Exception:
 | 
				
			||||||
 | 
					        traceback.print_exc()
 | 
				
			||||||
 | 
					        return False
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        return True
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user