mirror of
https://github.com/aquatix/digimarks.git
synced 2025-12-07 00:15:10 +01:00
Some fixes; function to add users through secret key
This commit is contained in:
30
digimarks.py
30
digimarks.py
@@ -10,6 +10,12 @@ from flask_peewee.db import Database
|
|||||||
from flask_peewee.utils import object_list
|
from flask_peewee.utils import object_list
|
||||||
from peewee import *
|
from peewee import *
|
||||||
|
|
||||||
|
try:
|
||||||
|
import settings
|
||||||
|
except ImportError:
|
||||||
|
print('Copy settings_example.py to settings.py and set the configuration to your own preferences')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# app configuration
|
# app configuration
|
||||||
APP_ROOT = os.path.dirname(os.path.realpath(__file__))
|
APP_ROOT = os.path.dirname(os.path.realpath(__file__))
|
||||||
MEDIA_ROOT = os.path.join(APP_ROOT, 'static')
|
MEDIA_ROOT = os.path.join(APP_ROOT, 'static')
|
||||||
@@ -28,6 +34,10 @@ app.config.from_object(__name__)
|
|||||||
db = Database(app)
|
db = Database(app)
|
||||||
|
|
||||||
|
|
||||||
|
def getkey():
|
||||||
|
return os.urandom(24).encode('hex')
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
username = CharField()
|
username = CharField()
|
||||||
key = CharField()
|
key = CharField()
|
||||||
@@ -35,9 +45,13 @@ class User(db.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Bookmark(db.Model):
|
class Bookmark(db.Model):
|
||||||
|
# Foreign key to User
|
||||||
|
userkey = CharField()
|
||||||
|
|
||||||
title = CharField()
|
title = CharField()
|
||||||
url = CharField()
|
url = CharField()
|
||||||
created_date = DateTimeField(default=datetime.datetime.now)
|
created_date = DateTimeField(default=datetime.datetime.now)
|
||||||
|
modified_date = DateTimeField(null=True)
|
||||||
#image = CharField(default='')
|
#image = CharField(default='')
|
||||||
url_hash = CharField()
|
url_hash = CharField()
|
||||||
tags = CharField()
|
tags = CharField()
|
||||||
@@ -88,7 +102,7 @@ def viewbookmark(urlhash):
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/<urlhash>/json')
|
@app.route('/<userkey>/<urlhash>/json')
|
||||||
def viewbookmark(urlhash):
|
def viewbookmarkjson(urlhash):
|
||||||
# bookmark = getbyurlhash()
|
# bookmark = getbyurlhash()
|
||||||
return bookmark
|
return bookmark
|
||||||
|
|
||||||
@@ -100,7 +114,7 @@ def editbookmark(urlhash):
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/<userkey>/add')
|
@app.route('/<userkey>/add')
|
||||||
def editbookmark():
|
def addbookmark():
|
||||||
bookmark = Bookmark()
|
bookmark = Bookmark()
|
||||||
return render_template('edit.html')
|
return render_template('edit.html')
|
||||||
|
|
||||||
@@ -122,6 +136,18 @@ def adding(userkey):
|
|||||||
return redirect(url)
|
return redirect(url)
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@app.route('/<systemkey>/adduser/')
|
||||||
|
def adduser(systemkey):
|
||||||
|
if systemkey == settings.SYSTEMKEY:
|
||||||
|
newuser = User()
|
||||||
|
newuser.key = getkey()
|
||||||
|
newuser.username = 'Nomen Nescio'
|
||||||
|
newuser.save()
|
||||||
|
else:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# create the bookmark table if it does not exist
|
# create the bookmark table if it does not exist
|
||||||
Bookmark.create_table(True)
|
Bookmark.create_table(True)
|
||||||
|
|||||||
0
settings_example.py
Normal file
0
settings_example.py
Normal file
Reference in New Issue
Block a user