Example #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,
        },
    })
Example #2
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
Example #3
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': '/'}})
Example #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
Example #5
0
    def __call__(self, request):
        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)

        return response
Example #6
0
 def get_composers(self):
     cache_key = "cr_pid_%s" % self.pid
     composers = [pickle.loads(i) for i in r.lrange(cache_key, 0, -1)]
     if not composers:
         cr_list = Copyright.objects.filter(pid=self.pid).all()
         for cr in cr_list:
             composer = Composer.get(cid=cr.cid)
             if composer:
                 composer.role = cr.roles
                 composers.append(composer)
                 r.lpush(cache_key, pickle.dumps(composer))
     return composers
Example #7
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
Example #8
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
Example #9
0
    def composers(self):
        """取出当前作品的所有作者"""
        # composers = []
        cache_key = 'cr_pid_%s' % self.pid
        composers = [pickle.loads(i) for i in r.lrange(cache_key, 0, -1)]
        # if r.exists(cache_key):

        if not composers:
            cr_list = Copyright.filter(pid=self.pid).all()

            for cr in cr_list:
                composer = Composer.get(cid= cr.cid)
                if composer:
                    composer.role = cr.roles
                    composers.append(composer)
                    r.lpush(cache_key,pickle.dumps(composer))
        return composers
Example #10
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",
    })
Example #11
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': '/'}})
Example #12
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_code(phone, code):
        return JsonResponse({
            "status": -1,
            "msg": "手机验证失败",
        })

    composer = Composer()
    composer.name = nickname
    composer.cid = composer.phone = phone
    composer.password = md5_pwd(phone, password)
    composer.avatar = ""
    composer.verified = 0
    composer.banner = ""
    composer.save()

    return JsonResponse({
        "status": 0,
        "data": {
            "callback": "/",
        }
    })
Example #13
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/',
        }
    })
Example #14
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
Example #15
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,
        }
    })
Example #16
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,
        }
    })
Example #17
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
Example #18
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/",
        }
    })