示例#1
0
def send_code(request):
    prefix_code = request.POST.get("prefix_code")
    phone = request.POST.get("phone")
    composer = Composer.get_by_phone(phone)
    if composer:
        return JsonResponse({
            "status": -1025,
            "msg": "该手机号已经注册过",
        })

    code = Code()
    code.phone = phone
    code.code = gen_code()
    code.ip = request.META["REMOTE_ADDR"]
    code.created_at = datetime.now()
    code.save()
    send_sms_code.delay(phone, code.code)
    return JsonResponse({
        "status": 0,
        "msg": "ok",
        "data": {
            "phone": phone,
            "prefix_code": prefix_code,
        },
    })
示例#2
0
def do_login(request):
    phone = request.POST.get('value')
    password = request.POST.get('password')
    composer = Composer.get_by_phone(phone)
    if not composer or composer.password != password:
        return JsonResponse({'status': -1, 'msg': '用户名密码错误'})
    return JsonResponse({'status': 0, 'data': {'callback': '/'}})
示例#3
0
def mobile_check(request):
    phone = request.POST.get("phone")
    code = request.POST.get("code")
    prefix_code = request.POST.get("prefix_code")
    composer = Composer.get_by_phone(phone)
    if not composer:
        return JsonResponse({
            "status": -1025,
            "msg": "该手机号未注册过",
        })
    if not verify_code(phone, code):
        return JsonResponse({"status": -1, "msg": "用户名或密码错误"})
    response = JsonResponse({
        "status": 0,
        "msg": "ok",
    })
    ls = str(random.randint(100000, 999999))
    response.set_cookie("laravel_session",
                        ls,
                        expires=datetime.now() + timedelta(minutes=5))
    response.set_cookie("phone",
                        phone,
                        expires=datetime.now() + timedelta(minutes=5))
    cache.set(phone, ls, timeout=60 * 5)
    return response
示例#4
0
def do_login(request):
    phone = request.POST.get('value')
    password = request.POST.get('password')
    composer = Composer.get_by_phone(phone)
    if not composer or composer.password != md5_pwd(phone, password):
        return JsonResponse({"status": -1, "msg": "用户名或密码错误"})
    response = JsonResponse({'status': 0, 'data': {'callback': '/'}})
    response.set_cookie('cid', composer.cid)
    response.set_cookie('token', md5_pwd(composer.cid, settings.SECRET_KEY))
    return response
示例#5
0
def do_login(request):
    phone = request.POST.get("phone")
    password = request.POST.get("password")
    composer = Composer.get_by_phone(phone)
    if not composer or composer.password != md5_pwd(phone, password):
        return JsonResponse({"status": -1, "msg": "用户名或密码错误"})

    response = JsonResponse({
        "status": 0,
        "data": {
            "callback": "/",
        }
    })
    response.set_cookie("cid", composer.cid)
    response.set_cookie("token", md5_pwd(composer.cid, settings.SECRET_KEY))
    return response
示例#6
0
def check_send(request):
    """发送手机验证码"""
    prefix_code = request.POST.get('prefix_code')
    phone = request.POST.get('phone')
    composer = Composer.get_by_phone(phone)
    if not composer:
        return JsonResponse({"status": -1025, "msg": "该手机号未注册"})
    code = Code()
    code.phone = phone
    code.code = gen_code()
    code.ip = request.META['REMOTE_ADDR']
    code.created_at = datetime.now()
    code.save()
    send_sms_code.delay(phone, code.code)
    return JsonResponse({
        "status": 0,
        "msg": "OK",
    })
示例#7
0
def reset_pwd(request):
    """修改密码"""
    phone = request.COOKIES.get('phone')
    password = request.POST.get('password')
    reset_password = request.POST.get('reset_password')
    if password != reset_password:
        return JsonResponse({"status": -10005, "msg": "两次输入的密码不正确"})
    if request.COOKIES.get('laravel_session') != cache.get(phone):
        return JsonResponse({"status": -1, "msg": "param error"})
    composer = Composer.get_by_phone(phone)
    composer.password = md5_pwd(phone, password)
    composer.save()
    return JsonResponse({
        "status": 0,
        "msg": "OK",
        'data': {
            'callback': '/login/',
        }
    })
示例#8
0
def do_login(request):
    """
    prefix_code:+86
type:phone
value:13664069165
password:123456
callback:http%3A%2F%2Fwww.xinpianchang.com%2F
    :param request:
    :return:
    """
    print('*' * 60)
    phone = request.POST.get('value')
    password = request.POST.get('password')
    composer = Composer.get_by_phone(phone)
    if not composer or password != md5_pwd(phone, password):
        return JsonResponse({"status": -1, "msg": "用户名或密码错误"})
    response = JsonResponse({'status': 0, 'data': {'callback': '/'}})
    response.set_cookie('cid', composer.cid)
    response.set_cookie('token', md5_pwd(composer.cid, settings.SECRET_KEY))
    return response
示例#9
0
def send_code(request):
    prefix_code = request.POST.get('prefix_code')
    phone = request.POST.get('phone')
    composer = Composer.get_by_phone(phone)
    if composer:
        return JsonResponse({'status': -1025, 'msg': '该手机号已注册过'})
    code = Code()
    code.phone = phone
    code.code = gen_code()
    code.ip = request.META['REMOTE_ADDR']
    code.created_at = datetime.now()
    code.save()
    send_sms_code(phone, code.code)
    return JsonResponse({
        'status': 0,
        'msg': 'ok',
        'data': {
            'phone': phone,
            'prefix_code': prefix_code,
        }
    })
示例#10
0
def send_code(request):
    """发送注册验证码"""
    prefix_code = request.POST.get('prefix_code')
    phone = request.POST.get('phone')
    composer = Composer.get_by_phone(phone)
    if composer:
        return JsonResponse({"status": -1025, "msg": "该手机号已注册过"})
    code = Code()
    code.phone = phone
    code.code = gen_code()
    code.ip = request.META['REMOTE_ADDR']
    code.created_at = datetime.now()
    code.save()
    send_sms_code.delay(phone, code.code)
    return JsonResponse({
        "status": 0,
        "msg": "OK",
        "data": {
            "phone": phone,
            "prefix_code": prefix_code,
        }
    })
示例#11
0
def mobile_check(request):
    """验证手机验证码"""
    phone = request.POST.get('phone')
    code = request.POST.get('code')
    prefix_code = request.POST.get('prefix_code')
    composer = Composer.get_by_phone(phone)
    if not composer:
        return JsonResponse({"status": -1025, "msg": "该手机号未注册过"})
    if not verify(phone, code):
        return JsonResponse({"status": -1, "msg": "手机验证失败"})
    response = JsonResponse({
        "status": 0,
        "msg": "OK",
    })
    ls = str(random.randint(100000, 999999))
    response.set_cookie('laravel_session',
                        ls,
                        expires=datetime.now() + timedelta(minutes=5))
    response.set_cookie('phone',
                        phone,
                        expires=datetime.now() + timedelta(minutes=5))
    cache.set(phone, ls, timeout=60 * 5)
    return response
示例#12
0
def reset_pwd(request):
    phone = request.COOKIES.get("phone")
    password = request.POST.get("password")
    reset_passsword = request.POST.get("reset_password")
    if password != reset_passsword:
        return JsonResponse({
            "status": -10005,
            "msg": "两次输入的密码不正确",
        })
    if request.COOKIES.get("laravel_session") != cache.get(phone):
        return JsonResponse({
            "status": -1,
            "msg": "param error",
        })
    composer = Composer.get_by_phone(phone)
    composer.password = md5_pwd(phone, password)
    composer.save()
    return JsonResponse({
        "status": 0,
        "msg": "ok",
        "data": {
            "callback": "/login/",
        }
    })