Esempio n. 1
0
 def post(self):
     self.parser.add_argument('username',
                              type=str,
                              help='This username cannot be blank',
                              required=True)
     self.parser.add_argument('password',
                              type=str,
                              help='This password cannot be blank',
                              required=True)
     data = self.parser.parse_args(
         strict=True)  # 获取传输的值/strict=True代表设置如果传以上未指定的参数主动报错
     if User.query.filter_by(username=data['username']).filter_by(
             flag=1).first():
         return {
             'msg': 'user {} already exists'.format(data['username'])
         }, 400
     new_user = User(username=data['username'],
                     password=User.hash_password(data['password']))
     session_add(new_user)
     msg = session_commit()
     if msg:
         return {
             "errors":
             f"{msg}",
             'msg':
             "user add failed at {0}".format(
                 time.strftime("%Y-%m-%d %H:%M:%S"))
         }, 500
     else:
         return {
             "msg":
             "user add successfully at {0}".format(
                 time.strftime("%Y-%m-%d %H:%M:%S"))
         }
Esempio n. 2
0
 def post(self):
     user_data = request.get_json()
     not_exist_fields = get_not_exist_fields(user_data.keys(), User)
     if not_exist_fields:
         return response(f"Unknown arguments: {not_exist_fields}", 404)
     form = RegisterForm(data=user_data)
     user_data['password'] = User.hash_password(user_data['password'])
     if form.validate():
         new_user = User(**user_data)
         session_add(new_user)
         msg = session_add(new_user)
         if msg:
             return response(f"{msg}", 500)
         else:
             return response("user create successfully")
     return response(form.errors, 400)
Esempio n. 3
0
 def post(self):
     api_data = request.get_json()
     not_exist_fields = get_not_exist_fields(api_data.keys(), ApiModel)
     if not_exist_fields:
         return response(f"Unknown arguments: {not_exist_fields}", 404)
     form = ApiForm(data=api_data)
     if form.validate():
         new_api = ApiModel(**api_data)
         session_add(new_api)
         msg = session_add(new_api)
         if msg:
             return response(f"{msg}", 500)
         else:
             return response("api add successfully at {0}".format(
                 time.strftime("%Y-%m-%d %H:%M:%S")))
     return response(form.errors, 400)
Esempio n. 4
0
 def post(self):
     data = request.get_json()
     print(data)
     not_exist_fields = get_not_exist_fields(data.keys(), Report)
     if not_exist_fields:
         return response(f"Unknown arguments: {not_exist_fields}", 404)
     new_report = Report(**data)
     msg = session_add(new_report)
     if msg:
         return response(f"{msg}", 500)
     else:
         return response("report add successfully at {0}".format(
             time.strftime("%Y-%m-%d %H:%M:%S")))