提交 a223c79eb0a484674bcb351396f53d2a24a39691

作者 qianyingz
1 个父辈 27989a74

bug fixed# 默认创建admin

... ... @@ -14,6 +14,8 @@ import configure
14 14 from app.decorators.auth_decorator import auth_decorator
15 15 import time
16 16 from app.models import SM3, AESHelper
  17 +from app.util.component.StructurePrint import StructurePrint
  18 +import traceback
17 19
18 20
19 21 def current_user():
... ... @@ -184,26 +186,29 @@ class DataManager(BlueprintApi):
184 186 @staticmethod
185 187 @bp.route("/init", methods=["GET"])
186 188 def init():
187   - username = 'admin'
188   - password = SM3.encode('DMap@123')
189   - if not User.query.filter_by(username=username).one_or_none():
190   - user = User(username=username, password=password, role='admin',
191   - phone='', company='', position='', email='',
192   - create_time=time.strftime(
193   - "%Y-%m-%d %H:%M:%S", time.localtime()),
194   - update_time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
195   - db.sesion.add(user)
196   - db.session.commit()
197   - return "创建默认用户成功"
198   - else:
199   - return "默认用户已存在"
200   -
  189 + try:
  190 + username = 'admin'
  191 + password = SM3.encode('DMap@123')
  192 + if not User.query.filter_by(username=username).one_or_none():
  193 + user = User(username=username, password=password, role='admin',
  194 + phone='', company='', position='', email='',
  195 + create_time=time.strftime(
  196 + "%Y-%m-%d %H:%M:%S", time.localtime()),
  197 + update_time=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
  198 + db.session.add(user)
  199 + db.session.commit()
  200 + return "创建默认用户成功"
  201 + else:
  202 + return "默认用户已存在"
  203 + except Exception as e:
  204 + StructurePrint().print(e.__str__()+":" + traceback.format_exc(), "error")
  205 +
201 206 @staticmethod
202 207 @bp.route("/translate", methods=["GET"])
203 208 def translate():
204   - password = ['esri@123','admin','DMap@123','passwd']
  209 + password = ['esri@123', 'admin', 'DMap@123', 'passwd']
205 210 result = {}
206 211 for p in password:
207 212 new_pwd = SM3.encode(p)
208 213 result[p] = new_pwd
209   - return result
\ No newline at end of file
  214 + return result
... ...
... ... @@ -38,7 +38,6 @@ class Api(ApiTemplate):
38 38 res["msg"] = "获取clients集合成功"
39 39 res["result"] = True
40 40 except Exception as e:
41   - db.session.rollback()
42 41 raise e
43 42 return res
44 43
... ...
... ... @@ -5,7 +5,6 @@
5 5
6 6 # import schedule
7 7 from flask import json
8   -from sqlalchemy import true
9 8 from .models import MonitorHost, MonitorInfo
10 9 from datetime import datetime, timedelta
11 10 import math
... ...
注册登录 后发表评论