Fix exception when trying to register existing user
This commit is contained in:
10
db/sqlite.py
10
db/sqlite.py
@@ -51,8 +51,10 @@ class DB:
|
||||
).fetchone()
|
||||
comments = db.execute('''
|
||||
select comment_id, parent_id, author_id, name, text, create_time, modify_time
|
||||
from comments, users
|
||||
where thread_id = ? and author_id = user_id
|
||||
from comments
|
||||
left join users
|
||||
on author_id = user_id
|
||||
where thread_id = ?
|
||||
''',
|
||||
(thread,)
|
||||
)
|
||||
@@ -293,6 +295,7 @@ class DB:
|
||||
return False
|
||||
|
||||
def add_user(self, username, password, time):
|
||||
try:
|
||||
db = self._db()
|
||||
c = db.cursor()
|
||||
c.execute('''
|
||||
@@ -305,6 +308,9 @@ class DB:
|
||||
db.commit()
|
||||
return True
|
||||
return False
|
||||
except sqlite3.IntegrityError:
|
||||
# User already exists, probably
|
||||
return False
|
||||
|
||||
def _db(self):
|
||||
return sqlite3.connect(self.conn)
|
||||
|
||||
2
main.py
2
main.py
@@ -274,7 +274,7 @@ def register():
|
||||
):
|
||||
flash('CAPTCHA answer is incorrect', 'error')
|
||||
elif not db.add_user(username, hash_password(password), time.time_ns()):
|
||||
flash('Failed to create user (username may already be taken)')
|
||||
flash('Failed to create account (username may already be taken)', 'error')
|
||||
else:
|
||||
flash('Account has been created. You can login now.', 'success')
|
||||
return redirect(url_for('index'))
|
||||
|
||||
Reference in New Issue
Block a user