초기 커밋: 인증 서버 분리
0bin-label-app 프로젝트의 auth 폴더에서 별도 리포지토리로 분리. Flask 기반 로그인 인증 서버: - POST /api/login: 클라이언트 로그인 API - GET /api/health: 서버 상태 확인 - /admin: 관리자 웹 페이지 - SQLite 기반 사용자 및 로그인 기록 저장 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
48
models.py
Normal file
48
models.py
Normal file
@@ -0,0 +1,48 @@
|
||||
# models.py
|
||||
# 인증 서버 데이터베이스 모델
|
||||
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from datetime import datetime
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
|
||||
class User(db.Model):
|
||||
"""사용자 모델"""
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(50), unique=True, nullable=False)
|
||||
password_hash = db.Column(db.String(255), nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
is_active = db.Column(db.Boolean, default=True)
|
||||
|
||||
# 관계: 로그인 기록
|
||||
login_logs = db.relationship('LoginLog', backref='user', lazy=True)
|
||||
|
||||
def set_password(self, password):
|
||||
"""비밀번호 해시 설정"""
|
||||
self.password_hash = generate_password_hash(password)
|
||||
|
||||
def check_password(self, password):
|
||||
"""비밀번호 확인"""
|
||||
return check_password_hash(self.password_hash, password)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<User {self.username}>'
|
||||
|
||||
|
||||
class LoginLog(db.Model):
|
||||
"""로그인 기록 모델"""
|
||||
__tablename__ = 'login_logs'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
login_time = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
ip_address = db.Column(db.String(50))
|
||||
user_agent = db.Column(db.String(255))
|
||||
success = db.Column(db.Boolean, default=True)
|
||||
|
||||
def __repr__(self):
|
||||
return f'<LoginLog {self.user_id} at {self.login_time}>'
|
||||
Reference in New Issue
Block a user