mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-07 00:15:10 +01:00
Moved key generation to User object itself; initialise its tags cache
This commit is contained in:
12
digimarks.py
12
digimarks.py
@@ -46,10 +46,6 @@ except AttributeError:
|
|||||||
all_tags = {}
|
all_tags = {}
|
||||||
|
|
||||||
|
|
||||||
def getkey():
|
|
||||||
return os.urandom(24).encode('hex')
|
|
||||||
|
|
||||||
|
|
||||||
def clean_tags(tags_list):
|
def clean_tags(tags_list):
|
||||||
tags_res = [x.strip() for x in tags_list]
|
tags_res = [x.strip() for x in tags_list]
|
||||||
tags_res = list(unique_everseen(tags_res))
|
tags_res = list(unique_everseen(tags_res))
|
||||||
@@ -65,6 +61,11 @@ class User(db.Model):
|
|||||||
key = CharField()
|
key = CharField()
|
||||||
created_date = DateTimeField(default=datetime.datetime.now)
|
created_date = DateTimeField(default=datetime.datetime.now)
|
||||||
|
|
||||||
|
def generate_key(self):
|
||||||
|
""" Generate userkey """
|
||||||
|
self.key = os.urandom(24).encode('hex')
|
||||||
|
return self.key
|
||||||
|
|
||||||
|
|
||||||
class Bookmark(db.Model):
|
class Bookmark(db.Model):
|
||||||
""" Bookmark instance, connected to User """
|
""" Bookmark instance, connected to User """
|
||||||
@@ -334,9 +335,10 @@ def adduser(systemkey):
|
|||||||
""" Add user endpoint, convenience """
|
""" Add user endpoint, convenience """
|
||||||
if systemkey == settings.SYSTEMKEY:
|
if systemkey == settings.SYSTEMKEY:
|
||||||
newuser = User()
|
newuser = User()
|
||||||
newuser.key = getkey()
|
newuser.generate_key()
|
||||||
newuser.username = 'Nomen Nescio'
|
newuser.username = 'Nomen Nescio'
|
||||||
newuser.save()
|
newuser.save()
|
||||||
|
all_tags[newuser.key] = []
|
||||||
return redirect('/' + newuser.key, code=302)
|
return redirect('/' + newuser.key, code=302)
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|||||||
Reference in New Issue
Block a user