完成基本审核功能

Change-Id: Ib93823f864d5340b034a37af4e4cb3fb2cd5491a
diff --git a/TRM/back/__pycache__/config.cpython-310.pyc b/TRM/back/__pycache__/config.cpython-310.pyc
index 02c50aa..47d55f3 100644
--- a/TRM/back/__pycache__/config.cpython-310.pyc
+++ b/TRM/back/__pycache__/config.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app.py b/TRM/back/app.py
index 5465905..3c7fb86 100644
--- a/TRM/back/app.py
+++ b/TRM/back/app.py
@@ -1,6 +1,8 @@
 from app import create_app
+from flask_cors import CORS
 
 app = create_app()
+CORS(app, resources={r"/*": {"origins": "*"}})
 
 if __name__ == "__main__":
     app.run(debug=True,port=5713,host='0.0.0.0')
\ No newline at end of file
diff --git a/TRM/back/app/__pycache__/__init__.cpython-310.pyc b/TRM/back/app/__pycache__/__init__.cpython-310.pyc
index 19d389d..f713fad 100644
--- a/TRM/back/app/__pycache__/__init__.cpython-310.pyc
+++ b/TRM/back/app/__pycache__/__init__.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/__pycache__/__init__.cpython-312.pyc b/TRM/back/app/__pycache__/__init__.cpython-312.pyc
index eaa8e71..ec28c7e 100644
--- a/TRM/back/app/__pycache__/__init__.cpython-312.pyc
+++ b/TRM/back/app/__pycache__/__init__.cpython-312.pyc
Binary files differ
diff --git a/TRM/back/app/__pycache__/routes.cpython-310.pyc b/TRM/back/app/__pycache__/routes.cpython-310.pyc
index 3293666..e1c6837 100644
--- a/TRM/back/app/__pycache__/routes.cpython-310.pyc
+++ b/TRM/back/app/__pycache__/routes.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/functions/Fpost.py b/TRM/back/app/functions/Fpost.py
index 5651e8b..2f07b4a 100644
--- a/TRM/back/app/functions/Fpost.py
+++ b/TRM/back/app/functions/Fpost.py
@@ -1,6 +1,8 @@
 from ..models.users import User as users
 from ..models.post import Post as post
-
+import secrets
+import hashlib
+from datetime import datetime, timedelta
 from sqlalchemy.orm import Session
 class Fpost:
     def __init__(self,session:Session):
@@ -23,9 +25,48 @@
         return True
     
     def review(self,postid,status):
+        print(status)
         res=self.session.query(post).filter(post.id==postid).first()
         if not res:
             return False
         res.status=status
         self.session.commit()
-        return True
\ No newline at end of file
+        return True
+    
+    def createtoken(self, userid):
+        """
+        根据userid创建token并插入到数据库
+        :param userid: 用户ID
+        :return: 生成的token字符串
+        """
+        # 生成随机盐值
+        salt = secrets.token_hex(16)
+        
+        # 创建哈希值:userid + 当前时间戳 + 随机盐值
+        current_time = str(datetime.now().timestamp())
+        hash_input = f"{userid}_{current_time}_{salt}"
+        
+        # 生成SHA256哈希值作为token
+        token = hashlib.sha256(hash_input.encode()).hexdigest()
+        
+        # 设置时间
+        created_time = datetime.now()
+        expires_time = created_time + timedelta(days=1)  # 一天后过期
+        
+        try:
+            # 创建新的token记录
+            new_token = Token(
+                token=token,
+                expires_at=expires_time,
+                created_at=created_time
+            )
+            
+            # 假设self.session是数据库会话对象
+            self.session.add(new_token)
+            self.session.commit()
+            
+            return token
+            
+        except Exception as e:
+            self.session.rollback()
+            raise Exception(f"创建token失败: {str(e)}")
\ No newline at end of file
diff --git a/TRM/back/app/functions/__pycache__/Fpost.cpython-310.pyc b/TRM/back/app/functions/__pycache__/Fpost.cpython-310.pyc
index fe0c6de..13abb35 100644
--- a/TRM/back/app/functions/__pycache__/Fpost.cpython-310.pyc
+++ b/TRM/back/app/functions/__pycache__/Fpost.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/models/__pycache__/__init__.cpython-310.pyc b/TRM/back/app/models/__pycache__/__init__.cpython-310.pyc
index f30dbeb..015de51 100644
--- a/TRM/back/app/models/__pycache__/__init__.cpython-310.pyc
+++ b/TRM/back/app/models/__pycache__/__init__.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/models/__pycache__/post.cpython-310.pyc b/TRM/back/app/models/__pycache__/post.cpython-310.pyc
index 263b592..8d33351 100644
--- a/TRM/back/app/models/__pycache__/post.cpython-310.pyc
+++ b/TRM/back/app/models/__pycache__/post.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/models/__pycache__/topics.cpython-310.pyc b/TRM/back/app/models/__pycache__/topics.cpython-310.pyc
index e291b93..fba569b 100644
--- a/TRM/back/app/models/__pycache__/topics.cpython-310.pyc
+++ b/TRM/back/app/models/__pycache__/topics.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/models/__pycache__/users.cpython-310.pyc b/TRM/back/app/models/__pycache__/users.cpython-310.pyc
index e6286c3..155a86c 100644
--- a/TRM/back/app/models/__pycache__/users.cpython-310.pyc
+++ b/TRM/back/app/models/__pycache__/users.cpython-310.pyc
Binary files differ
diff --git a/TRM/back/app/models/token.py b/TRM/back/app/models/token.py
new file mode 100644
index 0000000..cbe864b
--- /dev/null
+++ b/TRM/back/app/models/token.py
@@ -0,0 +1,27 @@
+from sqlalchemy import Column, Integer, String, DateTime, TIMESTAMP, Index
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.sql import func
+from datetime import datetime
+
+Base = declarative_base()
+
+class Token(Base):
+    __tablename__ = 'tokens'
+    
+    id = Column(Integer, primary_key=True, autoincrement=True)
+    token = Column(String(255), nullable=False, unique=True)
+    expires_at = Column(DateTime, nullable=False)
+    created_at = Column(TIMESTAMP, default=func.current_timestamp())
+    updated_at = Column(TIMESTAMP, default=func.current_timestamp(), onupdate=func.current_timestamp())
+    
+    __table_args__ = (
+        Index('idx_token', 'token'),
+        Index('idx_expires_at', 'expires_at'),
+    )
+    
+    def __repr__(self):
+        return f"<Token(id={self.id}, token='{self.token[:10]}...', expires_at={self.expires_at})>"
+    
+    def is_expired(self):
+        """检查token是否已过期"""
+        return datetime.now() > self.expires_at
\ No newline at end of file
diff --git a/TRM/back/app/routes.py b/TRM/back/app/routes.py
index 90c9c5c..19ff870 100644
--- a/TRM/back/app/routes.py
+++ b/TRM/back/app/routes.py
@@ -11,6 +11,7 @@
 @main.route('/apostlist',methods=['POST','GET'])
 def postlist():
     data=request.get_json()
+    print(data)
     engine=create_engine(Config.SQLURL)
     SessionLocal = sessionmaker(bind=engine)
     session = SessionLocal()
@@ -61,3 +62,19 @@
 
 
 
+@main.route('/nginxauth',methods=['POST','GET'])
+def nginxauth():
+    data=request.get_json()
+    engine=create_engine(Config.SQLURL)
+    SessionLocal = sessionmaker(bind=engine)
+    session = SessionLocal()
+    f=Fpost(session)
+    checres=f.checkid(data['userid'])
+    if(not checres):
+        return jsonify({'status': 'error', 'message': 'Unauthorized'})
+    
+    res=f.nginxauth(data['postid'],data['status'])
+    if not res:
+        return jsonify({'status': 'error', 'message': 'Post not found'})
+    
+    return jsonify({'status': 'success', 'message': 'Nginx auth updated successfully'})
\ No newline at end of file