Major update spanning pricing, market data, and analytics: - Pricing: Replace single-price service fees with 5-tier pricing for same-day, prime, and emergency deliveries across create/edit/finalize - Market: Add Ticker_Price and CompanyPrice models with endpoints for live commodity prices (HO, CL, RB) and competitor price tracking - Stats: Add daily/weekly/monthly gallons endpoints with multi-year comparison and YoY totals for the stats dashboard - Delivery: Add map and history endpoints, fix finalize null-driver crash - Schema: Change fill_location from INTEGER to VARCHAR(250), add pre_load normalization for customer updates, fix admin auth check Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
85 lines
2.1 KiB
Python
Executable File
85 lines
2.1 KiB
Python
Executable File
from flask_login import UserMixin, AnonymousUserMixin
|
|
from app import db, ma, login_manager
|
|
from datetime import datetime
|
|
from uuid import uuid4
|
|
|
|
|
|
def get_uuid():
|
|
return uuid4().hex
|
|
|
|
|
|
class Auth_User(UserMixin, db.Model):
|
|
__tablename__ = 'auth_users'
|
|
__table_args__ = {"schema": "public"}
|
|
|
|
id = db.Column(db.Integer,
|
|
autoincrement=True,
|
|
primary_key=True,
|
|
unique=True)
|
|
uuid = db.Column(db.String(32), default=get_uuid)
|
|
api_key = db.Column(db.TEXT)
|
|
username = db.Column(db.VARCHAR(40))
|
|
password_hash = db.Column(db.TEXT)
|
|
member_since = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
|
email = db.Column(db.VARCHAR(350))
|
|
last_seen = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
|
admin = db.Column(db.INTEGER)
|
|
admin_role = db.Column(db.INTEGER)
|
|
confirmed = db.Column(db.INTEGER)
|
|
active = db.Column(db.INTEGER, default=1)
|
|
|
|
def __init__(self,
|
|
username,
|
|
api_key,
|
|
password_hash,
|
|
member_since,
|
|
email,
|
|
last_seen,
|
|
admin,
|
|
admin_role,
|
|
confirmed,
|
|
active=1,
|
|
):
|
|
self.username = username
|
|
self.api_key = api_key
|
|
self.password_hash = password_hash
|
|
self.member_since = member_since
|
|
self.email = email
|
|
self.last_seen = last_seen
|
|
self.admin = admin
|
|
self.admin_role = admin_role
|
|
self.confirmed = confirmed
|
|
self.active = active
|
|
|
|
@property
|
|
def is_authenticated(self):
|
|
return True
|
|
|
|
@property
|
|
def is_active(self):
|
|
return True
|
|
|
|
@property
|
|
def is_anonymous(self):
|
|
return False
|
|
|
|
def get_id(self):
|
|
return self.id
|
|
|
|
|
|
class Auth_User_Schema(ma.SQLAlchemyAutoSchema):
|
|
class Meta:
|
|
model = Auth_User
|
|
|
|
|
|
user_schema = Auth_User_Schema()
|
|
users_schema = Auth_User_Schema(many=True)
|
|
|
|
|
|
class AnonymousUser(AnonymousUserMixin):
|
|
def __init__(self):
|
|
self.username = 'Guest'
|
|
|
|
|
|
login_manager.anonymous_user = AnonymousUser
|