62f550c373
Selbstgehostete Web-Cloud mit Dateiverwaltung, Kalender, Kontakte, Email-Webclient, Office-Viewer und Passwort-Manager. Backend (Flask/Python): - JWT-Auth mit Access/Refresh Tokens, Benutzerverwaltung - Dateien: Upload/Download, Ordner, Berechtigungen, Share-Links - Kalender: CRUD, Teilen, iCal-Export, CalDAV well-known URLs - Kontakte: Adressbuecher, vCard-Export, Teilen - Email: IMAP/SMTP-Proxy, Multi-Account - Office-Viewer: DOCX/XLSX/PPTX/PDF Vorschau - Passwort-Manager: AES-256-GCM clientseitig, KeePass-Import - Sync-API fuer Desktop/Mobile-Clients - SQLite mit WAL-Modus Frontend (Vue 3 + PrimeVue): - Datei-Explorer mit Breadcrumbs und Share-Dialogen - Monatskalender mit Event-Verwaltung - Kontaktliste mit Adressbuch-Sidebar - Email-Client mit 3-Spalten-Layout - Passwort-Manager mit TOTP und Passwort-Generator - Admin-Panel, Settings, oeffentliche Share-Seite Docker: Multi-Stage Build, Bind Mounts (keine Volumes) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
48 lines
2.1 KiB
Python
48 lines
2.1 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from app.extensions import db, bcrypt
|
|
|
|
|
|
class User(db.Model):
|
|
__tablename__ = 'users'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
username = db.Column(db.String(80), unique=True, nullable=False, index=True)
|
|
email = db.Column(db.String(255), unique=True, nullable=True)
|
|
password_hash = db.Column(db.String(255), nullable=False)
|
|
role = db.Column(db.String(20), default='user', nullable=False) # 'admin' or 'user'
|
|
master_key_salt = db.Column(db.LargeBinary, nullable=True) # For password manager
|
|
is_active = db.Column(db.Boolean, default=True, nullable=False)
|
|
storage_quota_mb = db.Column(db.Integer, default=5120) # 5 GB default
|
|
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
# Relationships
|
|
files = db.relationship('File', backref='owner', lazy='dynamic',
|
|
foreign_keys='File.owner_id')
|
|
calendars = db.relationship('Calendar', backref='owner', lazy='dynamic')
|
|
address_books = db.relationship('AddressBook', backref='owner', lazy='dynamic')
|
|
email_accounts = db.relationship('EmailAccount', backref='user', lazy='dynamic',
|
|
order_by='EmailAccount.sort_order')
|
|
password_folders = db.relationship('PasswordFolder', backref='owner', lazy='dynamic')
|
|
|
|
def set_password(self, password):
|
|
self.password_hash = bcrypt.generate_password_hash(password).decode('utf-8')
|
|
|
|
def check_password(self, password):
|
|
return bcrypt.check_password_hash(self.password_hash, password)
|
|
|
|
def to_dict(self, include_email=False):
|
|
data = {
|
|
'id': self.id,
|
|
'username': self.username,
|
|
'role': self.role,
|
|
'is_active': self.is_active,
|
|
'storage_quota_mb': self.storage_quota_mb,
|
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
|
}
|
|
if include_email:
|
|
data['email'] = self.email
|
|
return data
|