Пример #1
0
def create_user():
    """
    用户注册
    ---
    tags:
      - 用户相关接口
    description:
        用户注册接口,json格式
    parameters:
      - name: body
        description: 用户注册接口的body数据
        in: body
        type: object
        required: true
        schema:
          id: 用户
          required:
            - username
            - password
          properties:
            username:
              type: string
              description: 用户账号.
            name:
              type: string
              description: 用户名字.
            password:
              type: string
              description: 密码.
            email:
              type: string
              description: 邮箱.
            remark:
              type: string
              description: 备注.
            department_id:
              type: integer
              description: 部门id.
    responses:
      200:
        description: 
    """
    data = request.get_json()
    if not data:
        code = ResponseCode.InvalidParameter
        return ResMsg(code=code, data='You must post JSON data.').data

    user = User()
    user.from_dict(data, new_user=True)
    db.session.add(user)
    db.session.commit()

    return ResMsg(data='用户创建成功').data
Пример #2
0
from app.utils.core import db
from app.models.model import User, Department

from app.factory import create_app, celery_app
import json

app = create_app(config_name="PRODUCTION")
permissions = json.dumps({"hello": ["123", "456"]})
department = Department()
department.from_dict({
    "name": "管理员1",
    "describe": "管理员1",
    "permissions": permissions
})
db.session.add(department)
db.session.commit()

department_id = Department.query.filter_by(name="管理员1").first().get("id")
user = User()
user.from_dict(
    {
        "username": "******",
        "email": "*****@*****.**",
        "name": "admin1",
        "password": "******",
        "department_id": department_id
    },
    new_user=True)
db.session.add(user)
db.session.commit()