예제 #1
0
def forget_password_get_verification_code_view(request):
    resp = HttpResponse()
    # phone = request.user.username
    phone = request.GET.get("telephone")
    code = gSMSValidationMgr.ValidationAvailable(request, 'forgetpassword_sms_data')
    if code == '':
        if gSMSValidationMgr.isDebugCode(phone):
            validationTxt = phone
            gSMSValidationMgr.AddValidation(request, 'forgetpassword_sms_data', validationTxt)
            resp.write(make_success_msg())
        else:
            validationTxt = str(random.randrange(100000, 999999, 1))
            # ip = get_real_ip(request)
            ip = request.META['REMOTE_ADDR']
            if ip is not None:
                    # we have a real, public ip address for user
                sendSMS(ip, phone, validationTxt, ALI_SMS_API['SMS_ForgetPasswordTemplate'])
                gSMSValidationMgr.AddValidation(request, 'forgetpassword_sms_data', validationTxt)
                resp.write(make_success_msg())
            else:
                    # we don't have a real, public ip address for user
                resp.write(make_failed_msg("FakeIP"))
    else:
        resp.write(make_failed_msg("Too Fast"))
    return resp
예제 #2
0
def send_verification_code_view(request):
    data = request.GET
    resp = HttpResponse()
    phone = data['telephone']
    if User.objects.filter(username=phone).exists():
        resp.write( make_failed_msg('AlreadyRegistered') )
    else:
        code = gSMSValidationMgr.ValidationAvailable( request, 'register_sms_data')
        if code == '':
            if gSMSValidationMgr.isDebugCode(phone):
                validationTxt = phone
                gSMSValidationMgr.AddValidation(request, 'register_sms_data', validationTxt )
                resp.write( make_success_msg() )
            else:
                validationTxt = str(random.randrange(100000, 999999, 1))
                #ip = get_real_ip(request)
                ip = request.META['REMOTE_ADDR']
                if ip is not None:
                    # we have a real, public ip address for user
                    sendSMS(ip, phone, validationTxt, ALI_SMS_API['SMS_RegisterTemplate'])
                    gSMSValidationMgr.AddValidation(request, 'register_sms_data', validationTxt)
                    resp.write( make_success_msg())
                else:
                    # we don't have a real, public ip address for user
                    resp.write( make_failed_msg( "FakeIP" ))
        else:
            resp.write( make_failed_msg("Too Fast") )
    return resp