You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
Python
69 lines
1.4 KiB
Python
from datetime import datetime
|
|
from uuid import uuid4
|
|
|
|
from peewee import *
|
|
from PIL import Image
|
|
from flask_login import login_user
|
|
|
|
from flipbook import config
|
|
|
|
|
|
db = SqliteDatabase(f"data/flipbook.sqlite")
|
|
|
|
|
|
def rand_id():
|
|
return uuid4().hex
|
|
|
|
|
|
class Wallet(Model):
|
|
id = AutoField()
|
|
address = CharField(null=False, unique=True)
|
|
register_date = DateTimeField(default=datetime.utcnow)
|
|
login_date = DateTimeField(null=True)
|
|
opensea_handle = CharField(null=True)
|
|
twitter_handle = CharField(null=True)
|
|
nonce = CharField(default=rand_id())
|
|
nonce_date = DateTimeField(default=datetime.utcnow)
|
|
|
|
@property
|
|
def is_authenticated(self):
|
|
return True
|
|
|
|
@property
|
|
def is_active(self):
|
|
return True
|
|
|
|
@property
|
|
def is_anonymous(self):
|
|
return False
|
|
|
|
def generate_nonce(self):
|
|
return rand_id()
|
|
|
|
def change_nonce(self):
|
|
self.nonce = rand_id()
|
|
self.nonce_date = datetime.utcnow()
|
|
self.save()
|
|
|
|
def login(self):
|
|
self.change_nonce()
|
|
self.last_login_date = datetime.utcnow()
|
|
login_user(self)
|
|
self.save()
|
|
|
|
class Meta:
|
|
database = db
|
|
|
|
|
|
class Upload(Model):
|
|
id = AutoField()
|
|
token_id = IntegerField()
|
|
title = CharField()
|
|
text = CharField(null=True)
|
|
wallet = ForeignKeyField(Wallet)
|
|
image_name = CharField()
|
|
upload_date = DateTimeField(default=datetime.utcnow)
|
|
|
|
class Meta:
|
|
database = db
|