def logout(): """ 登出 :param form: :return: """ log.info("Parameter:{}".format('')) logout_user() return ajaxResponse.success(message='注销成功')
def deleteNode(form): try: model = Node.query.filter_by(node_id=form.node_id.data).first() if model is None: return ajaxResponse.fail(message='node_id 不存在,请更换') db.session.delete(model) db.session.commit() return ajaxResponse.success(message="删除成功") except Exception as e: log.error("错误 - {}".format(e)) db.session.rollback() raise ServerError()
def register(form): verify = User.query.filter_by(username=form.username.data).first() if verify: return ajaxResponse.fail(message='用户已存在') user = User() user.username = form.username.data user.password = generate_password_hash(form.password.data) try: mysql_db.session.add(user) mysql_db.session.commit() except: return ajaxResponse.fail(message='注册失败,请重试') return ajaxResponse.success(message="注册成功")
def login(form): # try: user = User.query.filter_by(username=form.username.data).first() print(user) if user is None: return ajaxResponse.fail(message='账号不存在,请重试') # 先加密再对比 if check_password_hash(user.password, form.password.data): remember = form.remember_me.data or False login_user(user, remember=remember) return ajaxResponse.success(message="登录成功") else: return ajaxResponse.fail(message='密码错误,请重试')
def getNode(form): try: model = Node.query.filter_by(node_id=form.node_id.data).first() if model is None: return ajaxResponse.fail('node不存在') data = { 'node_id': model.node_id, 'node_name': model.node_name, 'ip': model.ip, 'port': model.port, 'note': model.note, 'status': model.status } return ajaxResponse.success(message="保存成功", data=data) except Exception as e: log.error("错误 - {}".format(e)) raise ServerError()
def getToken(form): try: log.info("成功 - Parameter:{}".format(form)) user = User.objects(secret=form.secret.data).first() if user: expiration = current_app.config['TOKEN_EXPIRATION'] role = {1: "UserScope", 2: "AdminScope"} token = generate_auth_token(secret=form.secret.data, auth=role[user.role], expiration=expiration) model = {'token': token.decode('ascii')} return ajaxResponse.success(data=model, message="返回token成功") else: return ajaxResponse.fail(message="secret无效") except Exception as e: log.error("错误 - {}".format(e)) raise ServerError()
def getNodesList(): try: models = Node.query.all() datas = [] for model in models: data = { 'node_id': model.node_id, 'node_name': model.node_name, 'ip': model.ip, 'port': model.port, 'note': model.note, 'status': model.status } datas.append(data) return ajaxResponse.success(message="保存成功", data=datas) except Exception as e: log.error("错误 - {}".format(e)) raise ServerError()
def editNode(form): try: model = Node.query.filter_by(node_id=form.node_id.data).first() if model is None: return ajaxResponse.fail(message='node不存在') model.node_name = form.node_name.data model.ip = form.ip.data model.port = form.port.data model.note = form.note.data try: db.session.commit() except Exception: db.session.rollback() return ajaxResponse.fail('更新失败,可能部分字段已存在') return ajaxResponse.success(message="保存成功") except Exception as e: log.error("错误 - {}".format(e)) raise ServerError()
def addNode(form: AddNodeForm): try: hasName = Node.query.filter_by(node_name=form.node_name.data).first() if hasName: return ajaxResponse.fail(message='node_name 已存在,请更换') hasName = Node.query.filter_by(ip=form.ip.data, port=form.port.data).first() if hasName: return ajaxResponse.fail(message='ip:port 已存在,请更换') model = Node() model.node_name = form.node_name.data model.ip = form.ip.data model.port = form.port.data model.note = form.note.data db.session.add(model) db.session.commit() return ajaxResponse.success(message="新增成功") except Exception as e: log.error("错误 - {}".format(e)) db.session.rollback() raise ServerError()
def getProjectsList(form): try: return ajaxResponse.success(message="保存成功") except Exception as e: log.error("错误 - {}".format(e)) raise ServerError()