change username
This commit is contained in:
parent
c14a360418
commit
359b1d8af1
@ -35,6 +35,7 @@ class User:
|
|||||||
|
|
||||||
# check if username is already taken
|
# check if username is already taken
|
||||||
if self.db.fetchUserByUsername(input_username):
|
if self.db.fetchUserByUsername(input_username):
|
||||||
|
print("Username already taken")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# create sig for user
|
# create sig for user
|
||||||
@ -73,3 +74,20 @@ class User:
|
|||||||
print('Password updated')
|
print('Password updated')
|
||||||
else:
|
else:
|
||||||
print('Something went wrong while trying to update password..')
|
print('Something went wrong while trying to update password..')
|
||||||
|
|
||||||
|
def updateAccount(self):
|
||||||
|
# Get new username
|
||||||
|
new_username = input('Enter your new username: ')
|
||||||
|
|
||||||
|
# check if username is already taken
|
||||||
|
if self.db.fetchUserByUsername(new_username):
|
||||||
|
print("Username already taken")
|
||||||
|
return False
|
||||||
|
|
||||||
|
private_key_bytes = Signature.privateKeyToBytes(self.private_key)
|
||||||
|
|
||||||
|
if self.db.changeUsername(private_key_bytes, new_username) == True:
|
||||||
|
print('Username updated')
|
||||||
|
else:
|
||||||
|
print('Something went wrong while trying to update username..')
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class DatabaseHelper:
|
|||||||
|
|
||||||
def createUser(self, private_key, public_key, username, password):
|
def createUser(self, private_key, public_key, username, password):
|
||||||
if not self.conn:
|
if not self.conn:
|
||||||
return False
|
return None
|
||||||
try:
|
try:
|
||||||
self.cursor.execute("INSERT INTO `users` (private_key, public_key, username, password) VALUES (?, ?, ?, ?)", (private_key, public_key, username, password,))
|
self.cursor.execute("INSERT INTO `users` (private_key, public_key, username, password) VALUES (?, ?, ?, ?)", (private_key, public_key, username, password,))
|
||||||
self.commit()
|
self.commit()
|
||||||
@ -76,6 +76,37 @@ class DatabaseHelper:
|
|||||||
print(error)
|
print(error)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def changeUsername(self, user_privatekey, username):
|
||||||
|
if not self.conn:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Execute the query
|
||||||
|
try:
|
||||||
|
self.cursor.execute("UPDATE `users` SET username = ? WHERE `private_key` = ?", (username, user_privatekey,))
|
||||||
|
self.commit()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except sqlite3.Error as error:
|
||||||
|
print(error)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def deleteUser(self, user_privatekey):
|
||||||
|
# Check if the database is open
|
||||||
|
if not self.conn:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# Execute the query
|
||||||
|
try:
|
||||||
|
self.cursor.execute("DELETE FROM `users` WHERE `private_key` = ?", (user_privatekey, ))
|
||||||
|
self.commit()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except sqlite3.Error as error:
|
||||||
|
print(error)
|
||||||
|
return None
|
||||||
|
|
||||||
def fetchUserByUsername(self, username):
|
def fetchUserByUsername(self, username):
|
||||||
if not self.conn:
|
if not self.conn:
|
||||||
return None
|
return None
|
||||||
|
@ -164,7 +164,7 @@ class MenuHelper:
|
|||||||
print(user.private_key)
|
print(user.private_key)
|
||||||
|
|
||||||
case "Change username":
|
case "Change username":
|
||||||
print("TODO")
|
user.updateAccount()
|
||||||
|
|
||||||
case "Change password":
|
case "Change password":
|
||||||
user.updatePassword()
|
user.updatePassword()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user