-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
database.py
59 lines (44 loc) · 1.5 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from datetime import datetime
from mongoengine import Document
from mongoengine import (
StringField,
DateTimeField,
ReferenceField,
IntField,
BooleanField,
)
from flask_login import UserMixin
class User(Document, UserMixin, object):
username = StringField(required=True, unique=True, max_length=16, min_length=3)
hash = StringField(required=True)
email = StringField(required=False)
registration_date = DateTimeField(default=datetime.now)
admin = BooleanField(default=False)
def is_authenticated(self):
return True
def is_anonymous(self):
return False
def is_active(self):
return True
def get_id(self):
return self.username
meta = {"index": ["username"], "collection": "users"}
def __str__(self):
return self.username
class Paste(Document):
name = StringField(required=True, unique=True)
paste = StringField(required=True)
digest = StringField(required=False)
time = DateTimeField(required=True)
expire = DateTimeField(required=False)
user = ReferenceField(User, required=False)
views = IntField(required=False, default=0)
language = StringField(required=False)
address = StringField(required=False)
def __str__(self):
return self.name
class ApiKey(Document):
key = StringField(required=True, unique=True, max_length=32, min_length=32)
user = ReferenceField(User, required=True)
def __str__(self):
return "{0}:{1}".format(self.user, self.key)