fix: Don't allow user to create account with existing domain
This commit is contained in:
parent
90a86c2769
commit
3c98d9e243
@ -54,6 +54,9 @@ def create_user(email, domain, password):
|
||||
if db.search_users(email) != []:
|
||||
return {'success': False, 'message': 'User already exists'}
|
||||
|
||||
if db.search_users_domain(domain) != []:
|
||||
return {'success': False, 'message': 'Domain already exists'}
|
||||
|
||||
db.add_user(email, domain, hashed_password, token)
|
||||
return {'success': True, 'message': 'User created', 'token': token}
|
||||
|
||||
|
11
db.py
11
db.py
@ -64,6 +64,17 @@ def search_users(email):
|
||||
connection.close()
|
||||
return users
|
||||
|
||||
def search_users_domain(domain):
|
||||
connection = mysql.connector.connect(**dbargs)
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("""
|
||||
SELECT * FROM users WHERE domain = %s
|
||||
""", (domain,))
|
||||
users = cursor.fetchall()
|
||||
cursor.close()
|
||||
connection.close()
|
||||
return users
|
||||
|
||||
def search_users_token(token):
|
||||
connection = mysql.connector.connect(**dbargs)
|
||||
cursor = connection.cursor()
|
||||
|
Loading…
Reference in New Issue
Block a user