示例#1
0
文件: api.py 项目: gaosanshi/swiper
def login(request):
    phonenum = request.POST.get('phonenum')
    vcode = int(request.POST.get('vcode'))
    if check_vcode(phonenum, vcode):
        user = User.objects.get_or_create(phonenum=phonenum)
        request.session['uid'] = user.id
        return render_json(user.to_dict())
    else:
        return render_json(None, errors.VcodeError.code)
示例#2
0
def login(request):
    '''注册、登录'''
    phonenum = request.POST.get('phonenum')
    vcode = request.POST.get('vcode')
    if check_vcode(phonenum, vcode):
        user, created = User.objects.get_or_create(phonenum=phonenum)
        request.session['uid'] = user.id
        return render_json(user.to_dict())
    else:
        raise errors.VcodeError
示例#3
0
def login(request):
    #获取前端数据
    phone = request.POST.get('phone')
    vcode = request.POST.get('vcode')

    if check_vcode(phone,vcode):
        print('登录成功!@~')


    return JsonResponse({'msg':'ok'})
示例#4
0
文件: api.py 项目: SceneryCN/swiper
def login(request):
    phonenum = request.POST.get('phonenum')
    vcode = int(request.POST.get('vcode'))
    if not check_vcode(phonenum, vcode):
        user, created = User.get_or_create(phonenum=phonenum)
        request.session['uid'] = user.id
        pre_rcmd(user)
        return render_json(user.to_dict())
    else:
        raise errors.VcodeError
示例#5
0
文件: api.py 项目: Luciano0000/social
def login(request):

    phonenum = request.POST.get("phonenum")
    vcode = request.POST.get("vcode")
    if check_vcode(phonenum, vcode):
        raise errors.VcodeError
    else:
        user, created = User.objects.get_or_create(phonenum=phonenum)
        request.session['uid'] = user.id
        # uid是动态改变的,而且是唯一的一个key只对应一个value,假设当一个用户登录时uid=1,下一用户登录时uid就是=其他了
        pre_rcmd(user)
        return render_json(user.to_dict())
示例#6
0
def login(request):

    # 获取前端提交的数据
    phone = request.POST.get('phone')
    vcode = request.POST.get('vcode')

    # 检查用户的验证码是否正确
    if check_vcode(phone, vcode):
        print("登录成功!")

        user, created = User.objects.get_or_create(nickname=phone, phonenum=phone)

        request.session['uid'] = user.id

        return render_json(user.to_dict())

    else:
        print("验证码输入错误")
        return render_json("验证码错误", error.VCODE_ERROR)
示例#7
0
文件: apis.py 项目: modern0523/swiper
def login(request):
    # 获取前端提交的数据
    phone = request.POST.get('phone')
    vcode = request.POST.get('vcode')

    # 检查用户的验证码是否正确
    if check_vcode(phone, vcode):
        print("登录成功!")
        # 自动注册账号:给User表添加一条记录
        # User.objects.create(phonenum=phone)
        # 获取或者创建,如果没有该数据则创建并返回数据
        user, created = User.objects.get_or_create(nickname=phone,
                                                   phonenum=phone)
        # print(user, created)

        # 用session保存登录状态
        request.session['uid'] = user.id

        return render_json(user.to_dict())

    else:
        print("验证码输入错误")
        return render_json("验证码错误", errors.VCODE_ERROR)