コード例 #1
0
ファイル: auth.py プロジェクト: argush3/namex
def full_access_to_name_request(request: Request) -> bool:
    """Returns that the request contains the headers required to fully access this NR."""
    nr = request.headers.get('BCREG-NR', '')
    nrl = request.headers.get('BCREG-NRL', '')
    email = request.headers.get('BCREG-User-Email', '')
    phone = request.headers.get('BCREG-User-Phone', '')

    current_app.logger.debug('NR: %s, NRL: %s, Email: %s, Phone: %s', nr, nrl,
                             email, phone)

    nr = set_to_none(nr, ['none', 'null', 'nan'])
    nrl = set_to_none(nrl, ['none', 'null', 'nan'])
    email = set_to_none(email, ['none', 'null', 'nan'])
    phone = set_to_none(phone, ['none', 'null', 'nan'])

    if nr and not RequestDAO.validNRFormat(nr):
        nr = nr.replace(' ', '')
        nr = nr.replace('NR', '')
        nr = 'NR ' + nr

    if not (name_request := RequestDAO.find_by_nr(nr)):
        if not (name_request := RequestDAO.find_by_nr(nrl)):
            current_app.logger.debug(
                'Failed to find NR - NR: %s, NRL: %s, Email: %s, Phone: %s',
                nr, nrl, email, phone)
            return False
コード例 #2
0
    def common(nr, choice):
        """:returns: object, code, msg
        """
        if not RequestDAO.validNRFormat(nr):
            return None, None, jsonify(
                {'message': 'NR is not a valid format \'NR 9999999\''}), 400

        nrd = RequestDAO.find_by_nr(nr)
        if not nrd:
            return None, None, jsonify(
                {"message": "{nr} not found".format(nr=nr)}), 404

        name = nrd.names.filter_by(choice=choice).one_or_none()
        if not name:
            return None, None, jsonify({
                "message":
                "Choice {choice} for {nr} not found".format(choice=choice,
                                                            nr=nr)
            }), 404

        return nrd, name, None, 200