mirror of
				https://github.com/Kakune55/PyGetGPT.git
				synced 2025-10-31 03:54:41 +08:00 
			
		
		
		
	管理页登录系统完成
This commit is contained in:
		
							
								
								
									
										20
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								main.py
									
									
									
									
									
								
							| @@ -5,6 +5,7 @@ from apiModule import qwenTurbo , chatglmTurbo , gpt35Turbo , gpt4Turbo | |||||||
|  |  | ||||||
| app = flask.Flask(__name__) | app = flask.Flask(__name__) | ||||||
| CORS(app,origins="*") | CORS(app,origins="*") | ||||||
|  | app.secret_key = b'SQ-{kJE;m(jEBi|{yq]v' | ||||||
|  |  | ||||||
| @app.route('/api/user', methods=['POST']) | @app.route('/api/user', methods=['POST']) | ||||||
| def post_data(): | def post_data(): | ||||||
| @@ -49,10 +50,29 @@ def post_data(): | |||||||
|     db.reduce_value(userRequest['userkey'], tokenUsed) |     db.reduce_value(userRequest['userkey'], tokenUsed) | ||||||
|     return {"code":code,"output":output,"surplus":surplusToken} |     return {"code":code,"output":output,"surplus":surplusToken} | ||||||
|  |  | ||||||
|  |  | ||||||
| @app.route('/') | @app.route('/') | ||||||
| def index(): | def index(): | ||||||
|     return flask.render_template('index.html') |     return flask.render_template('index.html') | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @app.route('/login', methods=['POST','GET']) | ||||||
|  | def login(): | ||||||
|  |     if flask.request.method == 'GET': | ||||||
|  |         return flask.render_template('login.html') | ||||||
|  |     userRequest = flask.request.form | ||||||
|  |     if userRequest["password"] != config.readConf()["appconf"]["adminkey"]: | ||||||
|  |         return flask.render_template('login.html') | ||||||
|  |     flask.session["admin"] = True | ||||||
|  |     return flask.redirect(flask.url_for('admin')) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @app.route('/admin') | ||||||
|  | def admin(): | ||||||
|  |     if "admin" in flask.session : | ||||||
|  |         return "管理页" | ||||||
|  |     return "未登录" | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     app.run(debug=bool(config.readConf()["appconf"]["debug"]),host=config.readConf()["appconf"]["host"],port=config.readConf()["appconf"]["port"]) |     app.run(debug=bool(config.readConf()["appconf"]["debug"]),host=config.readConf()["appconf"]["host"],port=config.readConf()["appconf"]["port"]) | ||||||
							
								
								
									
										65
									
								
								templates/login.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								templates/login.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="zh-CN"> | ||||||
|  |  | ||||||
|  | <head> | ||||||
|  |     <meta charset="UTF-8"> | ||||||
|  |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|  |     <title>登录页面</title> | ||||||
|  |     <style> | ||||||
|  |         body { | ||||||
|  |             font-family: Arial, sans-serif; | ||||||
|  |             display: flex; | ||||||
|  |             justify-content: center; | ||||||
|  |             align-items: center; | ||||||
|  |             height: 100vh; | ||||||
|  |             margin: 0; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .login-container { | ||||||
|  |             padding: 20px; | ||||||
|  |             width: 300px; | ||||||
|  |             text-align: center; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .login-container h2 { | ||||||
|  |             margin-bottom: 20px; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .password-input { | ||||||
|  |             padding: 10px; | ||||||
|  |             margin-bottom: 10px; | ||||||
|  |             border: 1px solid #ccc; | ||||||
|  |             border-radius: 3px; | ||||||
|  |             width: 100%; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .login-button { | ||||||
|  |             padding: 10px 20px; | ||||||
|  |             border: none; | ||||||
|  |             border-radius: 3px; | ||||||
|  |             background-color: #5cb85c; | ||||||
|  |             color: white; | ||||||
|  |             cursor: pointer; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .login-button:hover { | ||||||
|  |             background-color: #4cae4c; | ||||||
|  |         } | ||||||
|  |     </style> | ||||||
|  | </head> | ||||||
|  |  | ||||||
|  | <body> | ||||||
|  |     <div class="login-container"> | ||||||
|  |         <h2>登录</h2> | ||||||
|  |         <form action="login" method="post"> | ||||||
|  |             <input name="password" type="password" id="password" class="password-input" placeholder="输入密码" required /> | ||||||
|  |             <button type="submit" class="login-button">登录</button> | ||||||
|  |         </form> | ||||||
|  |     </div> | ||||||
|  |  | ||||||
|  |     <script> | ||||||
|  |  | ||||||
|  |     </script> | ||||||
|  | </body> | ||||||
|  |  | ||||||
|  | </html> | ||||||
							
								
								
									
										73
									
								
								templates/status.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								templates/status.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | |||||||
|  | <!DOCTYPE html> | ||||||
|  | <html lang="zh-CN"> | ||||||
|  | <head> | ||||||
|  | <meta charset="UTF-8"> | ||||||
|  | <title>网站后台展示页</title> | ||||||
|  | <style> | ||||||
|  |   body { | ||||||
|  |     font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; | ||||||
|  |     background-color: #f7f7f7; | ||||||
|  |     padding: 20px; | ||||||
|  |   } | ||||||
|  |   .container { | ||||||
|  |     background-color: #fff; | ||||||
|  |     padding: 20px; | ||||||
|  |     border-radius: 8px; | ||||||
|  |     box-shadow: 0 0 10px rgba(0,0,0,0.1); | ||||||
|  |   } | ||||||
|  |   table { | ||||||
|  |     width: 100%; | ||||||
|  |     border-collapse: collapse; | ||||||
|  |   } | ||||||
|  |   th, td { | ||||||
|  |     border: 1px solid #ddd; | ||||||
|  |     padding: 8px; | ||||||
|  |     text-align: left; | ||||||
|  |   } | ||||||
|  |   th { | ||||||
|  |     background-color: #f2f2f2; | ||||||
|  |   } | ||||||
|  |   .green { | ||||||
|  |     color: green; | ||||||
|  |   } | ||||||
|  |   .red { | ||||||
|  |     color: red; | ||||||
|  |   } | ||||||
|  | </style> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | <div class="container"> | ||||||
|  |   <h2>网站后台展示页</h2> | ||||||
|  |   <table> | ||||||
|  |     <thead> | ||||||
|  |       <tr> | ||||||
|  |         <th>项目</th> | ||||||
|  |         <th>状态</th> | ||||||
|  |       </tr> | ||||||
|  |     </thead> | ||||||
|  |     <tbody> | ||||||
|  |       <tr> | ||||||
|  |         <td>网站访问速度</td> | ||||||
|  |         <td class="green">正常</td> | ||||||
|  |       </tr> | ||||||
|  |       <tr> | ||||||
|  |         <td>数据库连接</td> | ||||||
|  |         <td class="green">正常</td> | ||||||
|  |       </tr> | ||||||
|  |       <tr> | ||||||
|  |         <td>服务器负载</td> | ||||||
|  |         <td class="red">较高</td> | ||||||
|  |       </tr> | ||||||
|  |       <tr> | ||||||
|  |         <td>在线用户数</td> | ||||||
|  |         <td class="green">正常</td> | ||||||
|  |       </tr> | ||||||
|  |     </tbody> | ||||||
|  |   </table> | ||||||
|  | </div> | ||||||
|  |  | ||||||
|  | <script> | ||||||
|  | // 在这里可以添加一些交互逻辑,例如点击某个状态显示更多信息 | ||||||
|  | </script> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
		Reference in New Issue
	
	Block a user