예제 #1
0
def test_verify_with_valid_code4():
    country_code = '86'
    phone_number = '18510238421'
    sms_verification = SMSVerification.create_or_get_unused_verification_code(
        country_code, phone_number)
    assert False == SMSVerification.verify(country_code + '1', phone_number,
                                           sms_verification.serial_number,
                                           sms_verification.code)
예제 #2
0
파일: apiv1.py 프로젝트: gzxultra/sms
def phone_send_verification_code():
    country_code = request.form.get('country_code', '').strip()
    phone_number = request.form.get('phone_number', '').strip()
    is_async = request.form.get('mode', 'async').strip() == 'async'
    is_sms = request.form.get('send_mode', 'sms').strip() == 'sms'

    if not all([country_code, phone_number]):
        apiv1_logger.error(u'send_verification_code,%s,%s' %
                           (Apiv1Error.not_all_parameters_provided[0],
                            simplejson.dumps(request.form)))
        return error(Apiv1Error.not_all_parameters_provided)

    sms_verification = SMSVerification.create_or_get_unused_verification_code(
        country_code, phone_number)

    try:
        sms_verification.send(is_async=is_async, is_sms=is_sms)
    except SMSSendFailed as e:
        apiv1_logger.error(u'send_verification_code,%s,%s,%s' %
                           (Apiv1Error.send_verification_code_failed[0],
                            simplejson.dumps(request.form), e.message))

        return error(Apiv1Error.send_verification_code_failed)

    content = {
        'serial_number': sms_verification.serial_number,
        'country_code': country_code,
        'phone_number': phone_number
    }
    if not is_sms:
        content['called_show_num'] = Config.ALIDAYU_CALLED_SHOW_NUM
    return ok(content)
예제 #3
0
def test_reuse_verification(unused_and_not_expired_verification):
    sms_verification = SMSVerification.create_or_get_unused_verification_code(
        COUNTRY_CODE, PHONE_NUMBER)
    assert sms_verification.code == unused_and_not_expired_verification.code
    assert sms_verification.serial_number == unused_and_not_expired_verification.serial_number
    assert sms_verification.id == unused_and_not_expired_verification.id
    assert sms_verification.expire_time != unused_and_not_expired_verification.expire_time
예제 #4
0
파일: apiv1.py 프로젝트: gzxultra/sms
def verify_code():
    country_code = request.form.get('country_code', '').strip()
    phone_number = request.form.get('phone_number', '').strip()
    code = request.form.get('code', '').strip()

    if not all([country_code, phone_number, code]):
        apiv1_logger.error(u'verify_code,%s,%s' %
                           (Apiv1Error.not_all_parameters_provided[0],
                            simplejson.dumps(request.form)))

        return error(Apiv1Error.not_all_parameters_provided)

    # 测试服务器万能验证码
    if Config.DEBUG and code == '000000':
        return ok()

    if not SMSVerification.verify(country_code, phone_number, code):
        apiv1_logger.error(u'verify_code,%s,%s' %
                           (Apiv1Error.invalid_verification_code[0],
                            simplejson.dumps(request.form)))
        return error(Apiv1Error.invalid_verification_code)
    return ok()
예제 #5
0
def main():
    SMSProvider.create_table()
    SMSRecord.create_table()
    SMSProviderServiceArea.create_table()
    SMSVerification.create_table()
예제 #6
0
def unused_and_not_expired_verification(scope='module'):
    country_code = COUNTRY_CODE
    phone_number = PHONE_NUMBER
    sms_verification = SMSVerification.create_or_get_unused_verification_code(country_code, phone_number)
    return sms_verification
예제 #7
0
def test_reuse_verification(unused_and_not_expired_verification):
    sms_verification = SMSVerification.create_or_get_unused_verification_code(COUNTRY_CODE, PHONE_NUMBER)
    assert sms_verification.code == unused_and_not_expired_verification.code
    assert sms_verification.serial_number == unused_and_not_expired_verification.serial_number
    assert sms_verification.id == unused_and_not_expired_verification.id
    assert sms_verification.expire_time != unused_and_not_expired_verification.expire_time
예제 #8
0
def test_verify_with_valid_code4():
    country_code = '86'
    phone_number = '18510238421'
    sms_verification = SMSVerification.create_or_get_unused_verification_code(country_code, phone_number)
    assert False == SMSVerification.verify(country_code+'1', phone_number, sms_verification.serial_number, sms_verification.code)
예제 #9
0
def unused_and_not_expired_verification(scope='module'):
    country_code = COUNTRY_CODE
    phone_number = PHONE_NUMBER
    sms_verification = SMSVerification.create_or_get_unused_verification_code(
        country_code, phone_number)
    return sms_verification