Esempio n. 1
0
 def getButtonList(self, isLogin: bool):
     if isLogin:
         # MainLog.record(MainLog.level.DEBUG,"已登录")
         return JsonUtil().dictToJson([
             {
                 'title': '用户信息',
                 'url': '#userInfo'
             },
             {
                 'title': '面板',
                 'url': '/panel'
             },
             {
                 'title': '登出',
                 'url': '/user/logout'
             },
         ])
     else:
         # MainLog.record(MainLog.level.DEBUG,"未登录")
         return JsonUtil().dictToJson([
             {
                 'title': '关于',
                 'url': '#about'
             },
             {
                 'title': '登陆',
                 'url': '/user/login'
             },
             {
                 'title': '加入我们',
                 'url': '/user/register'
             },
         ])
 def getMenuDict(self):
     useList = [
         commonUse.copy(),
         my.copy(),
         peopleContro.copy(),
         adminContro.copy(),
     ]
     responUseList = []
     for i in range(useList.__len__()):
         childs = []
         useMenu = useList[i]
         for j in range(useMenu['child'].__len__()):
             child = useMenu['child'][j]
             if not child.get('permission'):
                 continue
             flag = False
             for permission in child['permission']:
                 if current_user.can(permission):
                     flag = True
                     break
             if flag:
                 # 返回json去除permission属性,防止窃取信息
                 childs.append({
                     'name': child['name'],
                     'url': child['url'],
                     'icoClass': child['icoClass'],
                 })
         if childs.__len__() != 0:
             responUseList.append(useList[i])
             useList[i]['child'] = childs
     return JsonUtil().dictToJson(responUseList)
Esempio n. 3
0
 def getMarkList(self, userId):
     userMarkDict = {
         'today': time.strftime("%Y-%m-%d", time.localtime()),
         'userMarkList': [],
     }
     for i in range(365):
         userMarkDict['userMarkList'].append({'markNum': 0})
     for markItem in self.__searchMarkByTimeAndUserId(
             self.__lastYearTime(), userId):
         # difference = int((datetime.datetime.now() - markItem.dateTime).days)
         difference = \
             int((
                 datetime.datetime(
                     datetime.datetime.now().year,
                     datetime.datetime.now().month,
                     datetime.datetime.now().day,
                     0,0,0) -
                 datetime.datetime(
                     markItem.dateTime.year,
                     markItem.dateTime.month,
                     markItem.dateTime.day,
                     0,0,0)
             ).days)
         if difference < 365 and difference >= 0:
             userMarkDict['userMarkList'][difference]['markNum'] += 1
     return JsonUtil().dictToJson(userMarkDict)
def getHeadPortrait(ID):
    try:
        return fileUtil.getFromRes(path="user/headPortrait", fileName=str(ID) + ".png")
    except Exception as e:
        MainLog.record(MainLog.level.WARN,"可能发生了盗取用户信息")
        MainLog.record(MainLog.level.WARN,e)
        return JsonUtil().dictToJson(errorUtil.getData('backEndWrong2'))
Esempio n. 5
0
 def getLoginNotice(self, show: bool = False):
     loginNoticeList = []
     if show:
         LoginNoticeQueryList = LoginNotice.query.filter_by(
             isShow=True).all()
     else:
         LoginNoticeQueryList = LoginNotice.query.filter_by().all()
     for loginNotice in LoginNoticeQueryList:
         loginNoticeList.append({
             'id':
             loginNotice.id,
             'authorId':
             loginNotice.authorId,
             'date':
             loginNotice.date.strftime("%Y-%m-%d %H:%M:%S"),
             'title':
             loginNotice.title,
             'content':
             loginNotice.content,
             'isShow':
             loginNotice.isShow,
             'backgroundImageSrc':
             loginNotice.backgroundImageSrc,
         })
     return JsonUtil().dictToJson(loginNoticeList)
Esempio n. 6
0
def editMyBaseData():
    form = EditMyBaseData(request.form)
    if form.validate_on_submit():
        if userControler.editUser(current_user.id, form):
            return successUtil.getData('editMyBaseDataSuccess')
        else:
            return errorUtil.getData('dataBaseError')
    return errorUtil.getData('FormDataWrong',
                             message=JsonUtil().dictToJson(form.errors))
 def getData(self, typeName: str = "backEndWrong0", message: str = ""):
     type = self.InformationTypeDict.get(typeName)
     if type is None:
         return JsonUtil().dictToJson({
             "type": 2,
             "content": self.InformationDict[2],
         })
     if message == "":
         return JsonUtil().dictToJson({
             "type": type,
             "content": self.InformationDict[type],
         })
     else:
         return JsonUtil().dictToJson({
             "type": type,
             "content": self.InformationDict[type],
             "message": message,
         })
Esempio n. 8
0
 def getUserListData(self,listWords):
     searchFile = [
         User.schoolID,
         User.nickName,
     ]
     responUserList = []
     userIdList = []
     for file in searchFile:
         self.__searchByFuzzyRule(responUserList,userIdList,file,listWords)
     for index in range(responUserList.__len__()):
         responUserList[index] = responUserList[index].toDict()
     return JsonUtil().dictToJson(responUserList)
def register():
    if current_user.is_authenticated:
        return redirect(url_for('panel.index'))
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            if form.validate_userName(form.schoolNum):
                if form.validata_Num():
                    if userControler.addUser(form):
                        return successUtil.getData('registerSuccess')
                    else:
                        return errorUtil.getData('backEndWrong2')
                return errorUtil.getData('FormDataWrong')
            return errorUtil.getData('UserNameExist')
        return errorUtil.getData('FormDataWrong',message=JsonUtil().dictToJson(form.errors))
    return render_template('newRegister.html', form=form)
def login():
    if current_user.is_authenticated:
        return redirect(url_for('panel.index'))
    # TAG 测试时关闭csrf保护,接口开发完毕打开
    form = LoginForm(request.form,csrf_enabled=False)
    if request.method == 'POST':
        if form.validate():
            user = User.query.filter_by(schoolID=form.userName.data).first()
            if user is not None:
                if user.verify_password(form.password.data):
                    login_user(user)
                    return successUtil.getData('loginSuccess')
                return errorUtil.getData('PasswordWrong')
            return errorUtil.getData('UserNameNone')
        return errorUtil.getData('FormDataWrong',message=JsonUtil().dictToJson(form.errors))
    return render_template('login.html', form=form)
Esempio n. 11
0
    def uploadToS3(type, file_name, data, localPath=''):
        system_path = os.getcwd() + '/'
        config_data = ju.jsonToDictionary(
            FileSystem.getDataFromFile(system_path + "config.json"))

        config_data = config_data.get('s3_bucket')
        if type == 'file':
            client = boto3.client(
                's3',
                region_name=config_data.get('region_name'),
                aws_access_key_id=config_data.get('accesskey'),
                aws_secret_access_key=config_data.get('secretkey'))
            client.upload_file(file_name, config_data.get('serverPath'), data)
        else:
            session = boto3.resource(
                's3',
                region_name=config_data.get('region_name'),
                aws_access_key_id=config_data.get('accesskey'),
                aws_secret_access_key=config_data.get('secretkey'))
            session.Bucket(config_data.get('serverPath')).put_object(
                Key=file_name, Body=data)
Esempio n. 12
0
def editLaboratory():
    form = EditLaboratory(request.form)
    if form.validate_on_submit():
        return "0"
    return errorUtil.getData('FormDataWrong',
                             message=JsonUtil().dictToJson(form.errors))
Esempio n. 13
0
def data():
    return JsonUtil().dictToJson(current_user.toDict())
def getProfessionalList():
    return JsonUtil().dictToJson(ProfessionalClass.getDict())
def getLaboratory():
    return JsonUtil().dictToJson(Laboratory.getDict())
def getDirection():
    return JsonUtil().dictToJson(Direction.getDict())