From 1c8853341a26dea16dc42d8e087390d91cd63f3d Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 12:15:28 +0100 Subject: [PATCH 1/3] check if account already exists #37 --- frontend.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend.py b/frontend.py index 37144d3..0ea9d1f 100755 --- a/frontend.py +++ b/frontend.py @@ -56,6 +56,9 @@ def register_post(): @get('/confirm//') @view('template/propaganda.tpl') def confirm(city, token): + # check whether city already exists + if db.by_city(city): + return dict(error='Account already exists.') # create db-entry if db.confirm(token, city): # :todo show info "Account creation successful." From 2ce27fc52f845b1c238bb6d6a7724a33059cc4f4 Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 13:21:47 +0100 Subject: [PATCH 2/3] nicer error messages --- frontend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend.py b/frontend.py index 0ea9d1f..63143d5 100755 --- a/frontend.py +++ b/frontend.py @@ -58,12 +58,13 @@ def register_post(): def confirm(city, token): # check whether city already exists if db.by_city(city): - return dict(error='Account already exists.') + return dict(error='This Account was already confirmed, please try ' + 'signing in.') # create db-entry if db.confirm(token, city): # :todo show info "Account creation successful." redirect('/settings') - return dict(error='Email confirmation failed.') + return dict(error='Account creation failed. Please try to register again.') @post('/login') From 76b3b574f00bff4b386e97447c7a2e95e5bbaebe Mon Sep 17 00:00:00 2001 From: b3yond Date: Fri, 11 Jan 2019 13:23:37 +0100 Subject: [PATCH 3/3] replaced attribute with get call --- db.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/db.py b/db.py index 811d197..61100ae 100644 --- a/db.py +++ b/db.py @@ -14,7 +14,6 @@ class DB(object): self.conn = sqlite3.connect(dbfile) self.cur = self.conn.cursor() self.create() - self.secret = self.get_secret() def execute(self, *args, **kwargs): return self.cur.execute(*args, **kwargs) @@ -189,7 +188,7 @@ class DB(object): 'passhash': scrypt_mcf( password.encode('utf-8') ).decode('ascii') - }, self.secret).decode('ascii') + }, self.get_secret()).decode('ascii') def mail_subscription_token(self, email, city): """ @@ -203,17 +202,17 @@ class DB(object): token = jwt.encode({ 'email': email, 'city': city - }, self.secret).decode('ascii') + }, self.get_secret()).decode('ascii') return token def confirm_subscription(self, token): - json = jwt.decode(token, self.secret) + json = jwt.decode(token, self.get_secret()) return json['email'], json['city'] def confirm(self, token, city): from user import User try: - json = jwt.decode(token, self.secret) + json = jwt.decode(token, self.get_secret()) except jwt.DecodeError: return None # invalid token if 'passhash' in json.keys():