示例#1
0
def add():
    """Add user
    ---
    tags:
      - users
    consumes:
      - application/json
    parameters:
      - name: body
        in: body
        required: true
        schema:
          id: AddUser
          required:
            - name
            - email_address
            - user_type
            - password
          properties:
            name:
              type: string
            email_address:
              type: string
            password:
              type: string
            user_type:
              type: string
            framework:
              type: string
            shared_application_id:
              type: string
    responses:
      200:
        description: User
        type: object
        properties:
          role:
            type: string
          email_address:
            type: string
          name:
            type: string
          supplier_code:
            type: string
          application_id:
            type: string
    """
    return create_user()
示例#2
0
def add(token):
    """Creates a new user based on the token claim and email address provided.
    ---
    tags:
      - users
    consumes:
      - application/json
    parameters:
      - name: e
        in: query
        type: string
        required: true
        description: URL encoded email address
      - name: token
        in: path
        type: string
        required: true
        description: the validation token
      - name: body
        in: body
        required: true
        schema:
          required:
            - password
          properties:
            password:
              type: string
    responses:
      200:
        description: User
        type: object
        properties:
          role:
            type: string
          email_address:
            type: string
          name:
            type: string
          supplier_code:
            type: string
          application_id:
            type: string
    """
    email_address_encoded = request.args.get('e') or ''
    if not email_address_encoded:
        return jsonify(message='You must provide an email address when validating a new account'), 400
    email_address = unquote_plus(email_address_encoded)
    json_payload = request.get_json()
    password = json_payload.get('password', None)
    if not password:
        return jsonify(message='You must provide a password for your new user account'), 400
    claim = user_claims_service.find(type='signup', token=token, email_address=email_address,
                                     claimed=False).one_or_none()
    if not claim:
        return jsonify(message='Invalid token'), 400
    user = create_user(
        user_type=claim.data['user_type'],
        name=claim.data['name'],
        email_address=email_address,
        password=password,
        framework=claim.data['framework'],
        supplier_code=claim.data.get('supplier_code', None)
    )
    try:
        claim = user_claims_service.validate_and_update_claim(type='signup', token=token, email_address=email_address)
        if not claim:
            return jsonify(message='Invalid token'), 400
    except Exception as error:
        return jsonify(message='Invalid token'), 400

    publish_tasks.user_claim.delay(
        publish_tasks.compress_user_claim(claim),
        'updated'
    )

    return user
示例#3
0
def add_deprecated():
    return create_user()
示例#4
0
def add(token):
    """Creates a new user based on the token claim and email address provided.
    ---
    tags:
      - users
    consumes:
      - application/json
    parameters:
      - name: e
        in: query
        type: string
        required: true
        description: URL encoded email address
      - name: token
        in: path
        type: string
        required: true
        description: the validation token
      - name: body
        in: body
        required: true
        schema:
          required:
            - password
          properties:
            password:
              type: string
    responses:
      200:
        description: User
        type: object
        properties:
          role:
            type: string
          email_address:
            type: string
          name:
            type: string
          supplier_code:
            type: string
          application_id:
            type: string
    """
    email_address_encoded = request.args.get('e') or ''
    if not email_address_encoded:
        return jsonify(
            message=
            'You must provide an email address when validating a new account'
        ), 400
    email_address = unquote_plus(email_address_encoded)
    json_payload = request.get_json()
    password = json_payload.get('password', None)
    if not password:
        return jsonify(
            message='You must provide a password for your new user account'
        ), 400
    claim = user_claims_service.get_claim(type='signup',
                                          token=token,
                                          email_address=email_address,
                                          claimed=False)
    headers = {}
    for x in request.headers:
        headers[x[0]] = x[1]
    if not claim:
        current_app.logger.info('login.signup.fail: 1 {email_address}',
                                extra={'email_address': email_address})
        current_app.logger.info('login.signup.headers: {headers}',
                                extra={'headers': headers})
        return jsonify(message='Invalid token'), 400
    user = create_user(user_type=claim.data['user_type'],
                       name=claim.data['name'],
                       email_address=email_address,
                       password=password,
                       framework=claim.data['framework'],
                       supplier_code=claim.data.get('supplier_code', None),
                       abn=claim.data.get('abn', None))
    try:
        claim = user_claims_service.validate_and_update_claim(
            type='signup', token=token, email_address=email_address)
        if not claim:
            current_app.logger.info('login.signup.fail: 2 {email_address}',
                                    extra={'email_address': email_address})
            current_app.logger.info('login.signup.headers: {headers}',
                                    extra={'headers': headers})
            return jsonify(message='Invalid token'), 400
    except Exception as error:
        current_app.logger.info(
            'login.signup.fail: 3 {email_address} {exception}',
            extra={
                'email_address': email_address,
                'exception': str(error)
            })
        current_app.logger.info('login.signup.headers: {headers}',
                                extra={'headers': headers})
        return jsonify(message='Invalid token'), 400

    publish_tasks.user_claim.delay(publish_tasks.compress_user_claim(claim),
                                   'updated')

    return user