Allow adding users from the admin panel

This commit is contained in:
David Hoppenbrouwers
2022-10-09 14:55:49 +02:00
parent 650130d33c
commit f4e543b1f7
3 changed files with 46 additions and 2 deletions

View File

@@ -360,7 +360,10 @@ class DB:
return True
return False
def add_user(self, username, password, time):
def register_user(self, username, password, time):
'''
Add a user if registrations are enabled.
'''
try:
db = self._db()
c = db.cursor()
@@ -380,6 +383,27 @@ class DB:
# User already exists, probably
return False
def add_user(self, username, password, time):
'''
Add a user without checking if registrations are enabled.
'''
try:
db = self._db()
c = db.cursor()
c.execute('''
insert into users(name, password, join_time)
values (lower(?), ?, ?)
''',
(username, password, time)
)
if c.rowcount > 0:
db.commit()
return True
return False
except sqlite3.IntegrityError:
# User already exists, probably
return False
def get_users(self):
return self._db().execute('''
select user_id, name, join_time, role, banned_until