Skip to content

Commit

Permalink
2024年6月14日 feat(manage.py) 初始化token
Browse files Browse the repository at this point in the history
  • Loading branch information
ss1917 committed Jun 14, 2024
1 parent 4f1c72f commit 07dddf8
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import getpass
from datetime import datetime
Expand All @@ -7,8 +10,11 @@

from sqlalchemy import create_engine, text
from websdk2.consts import const

from websdk2.jwt_token import AuthToken
from settings import settings as app_settings
from websdk2.configs import configs

if configs.can_import: configs.import_dict(**app_settings)

default_configs = app_settings[const.DB_CONFIG_ITEM][const.DEFAULT_DB_KEY]

Expand Down Expand Up @@ -112,6 +118,24 @@ def handle(self):
print(f"Create SuperUser Success: {username}")


class AuthKeyInit(BaseCommand):
"""
Token初始化
"""

def handle(self):
auth_token = AuthToken()
token = auth_token.encode_auth_token_v2(
exp_days=1825, # 五年
user_id=99999, # You should replace this with the actual user_id
username="codo",
nickname="系统用户",
email="[email protected]",
is_superuser=True
)
print(token)


def execute_from_command_line(argv):
"""解析命令行参数并执行相应的命令"""
if len(argv) < 2:
Expand All @@ -132,6 +156,10 @@ def execute_from_command_line(argv):
goodbye_parser = subparsers.add_parser('db_init', help='used to db init.')
goodbye_parser.set_defaults(func=DBInit.handle)

# 添加子命令 'token_init'
key_parser = subparsers.add_parser('token_init', help='used to auth key init.')
key_parser.set_defaults(func=AuthKeyInit.handle)

# 解析命令行参数
args = parser.parse_args()
# 调用相应的子命令处理函数
Expand Down

0 comments on commit 07dddf8

Please sign in to comment.