Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def __call__(self, request):
        # Code to be executed for each request before
        # the view (and later middleware) are called.
        if request.path in need_login:
            cid = request.COOKIES.get('cid')
            token = request.COOKIES.get('token')
            if not cid or md5_pwd(cid, settings.SECRET_KEY) != token:
                return HttpResponseRedirect('/login/')
            request.composer = Composer.get(cid=cid)
        response = self.get_response(request)

        # Code to be executed for each request/response after
        # the view is called.

        return response
Exemplo n.º 4
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/',
        }
    })
Exemplo n.º 5
0
def do_register(request):
    nickname = request.POST.get('nickname')
    phone = request.POST.get('phone')
    code = request.POST.get('code')
    password = request.POST.get('password')
    prefix_code = request.POST.get('prefix_code')
    callback = request.POST.get('callback')
    if Composer.objects.filter(phone=phone).exists():
        data = {'status': -1025, 'msg': '该手机号已经注册过'}
        return JsonResponse(data)
    if not verify(phone, code):
        return JsonResponse({'status': -1, 'msg': '手机验证失败'})
    composer = Composer()
    composer.cid = composer.phone = phone
    composer.name = nickname
    composer.password = md5_pwd(phone, password)
    composer.avatar = ''
    composer.banner = ''
    composer.save()
    return JsonResponse({'status': 0, 'data': {'callback': '/'}})