示例#1
0
def login_sms(request):
    """短信验证登录"""
    if request.method == 'GET':
        form = LoginSMSForm()

        context = {
            'form': form,
        }
        return render(request, 'web/login_sms.html', context)

    if request.method == "POST":
        form = LoginSMSForm(request.POST)

        if form.is_valid():
            # 验证成功,登录
            mobile_phone = form.cleaned_data['mobile_phone']
            user = models.UserInfo.objects.filter(
                mobile_phone=mobile_phone).first()
            # 登录成功写入session中
            request.session['user_id'] = user.id
            request.session.set_expiry(60 * 60 * 24 * 7)

            return JsonResponse({"code": 200, "msg": '/index/'})
        else:
            return JsonResponse({"code": 406, "msg": form.errors})
示例#2
0
def login_sms(request):
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'login_sms.html', {'form': form})
    form = LoginSMSForm(request.POST)
    if form.is_valid():
        user_obj = form.cleaned_data['mobile_phone']
        request.session['user_id'] = user_obj.id
        request.session['user_name'] = user_obj.username
        return JsonResponse({'status': True, 'data': '/index/'})
    return JsonResponse({'status': False, 'error': form.errors})
示例#3
0
def login_sms(request):
    """ 短信登录 """
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'login_sms.html', {'form': form})

    form = LoginSMSForm(request.POST)
    if form.is_valid():
        user_object = form.cleaned_data['mobile_phone']
        # 保存用户名到session中
        request.session['user_id'] = user_object.pk
        request.session.set_expiry(60 * 60 * 24 * 14)
        return JsonResponse({'status': True, 'data': '/index/'})
    return JsonResponse({'status': False, 'error': form.errors})
示例#4
0
文件: account.py 项目: zhldestiny/s28
def login_sms(request):
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'web/login_sms.html', {"form": form})
    form = LoginSMSForm(request.POST)
    if form.is_valid():
        phone = form.cleaned_data["phone"]

        # 把用户名写入seesion中
        user_object = models.UserInfo.objects.filter(phone=phone).first()
        request.session['user_id'] = user_object.id
        request.session.set_expiry(60 * 60 * 24 * 14)  # session 默认有效时间为两周
        return JsonResponse({"status": True, 'data': "/index/"})

    return JsonResponse({"status": False, 'error': form.errors})
示例#5
0
def login_sms(request):
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'login_sms.html', {'form': form})
    form = LoginSMSForm(request.POST)
    if form.is_valid():
        # 用户输入正确,登录成功
        mobile_phone = form.cleaned_data['mobile_phone']
        #  用户信息放入session
        user_object = models.UserInfo.objects.filter(mobile_phone=mobile_phone).first()
        request.session['user_id'] = user_object.id
        request.session.set_expiry(60 * 60 * 24 * 24)  # 主动修改session的过期时间
        print(user_object.username, user_object.email)
        return JsonResponse({"status": True, 'data': "/index/"})
    return JsonResponse({"status": False, 'error': form.errors})
示例#6
0
def login_sms(request):
    """login via sms"""
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'login_sms.html', {'form': form})

    form = LoginSMSForm(request.POST)
    if form.is_valid():
        # If the detail is correct
        mobile_phone = form.cleaned_data['mobile_phone']
        # Write username into session
        user_object = models.UserInfo.objects.filter(
            mobile_phone=mobile_phone).first()
        request.session['user_id'] = user_object.id
        request.session['user_name'] = user_object.username
        return JsonResponse({'status': True, 'data': "/index/"})
    return JsonResponse({'status': False, 'error': form.errors})
示例#7
0
def login_sms(request):
    """
    短信登录
    :param request:
    :return:
    """
    if request.method == "GET":
        form = LoginSMSForm()
        return render(request, "login_sms.html", {"form": form})
    form = LoginSMSForm(request.POST)
    if form.is_valid():
        # 用户输入正确,登录成功
        user_object = form.cleaned_data['mobile_phone']
        # 用户信息放入session
        request.session["user_id"] = user_object.id
        # request.session["user_name"] = user_object.username
        request.session.set_expiry(60 * 60 * 24 * 14)
        return JsonResponse({"status": True, "data": "/index/"})
    return JsonResponse({"status": False, "error": form.errors})
示例#8
0
def login_sms(request):
    """ 短信登录 """
    if request.method == "GET":
        form = LoginSMSForm()
        return render(request, "login_sms.html", {"form": form})
    form = LoginSMSForm(request.POST)
    if form.is_valid():
        # 用户输入正确,登录成功
        mobile_phone = form.cleaned_data["mobile_phone"]

        # 把用户名写入到session中
        user_object = models.UserInfo.objects.filter(
            mobile_phone=mobile_phone).first()
        request.session["user_id"] = user_object.id
        request.session.set_expiry(59 * 60 * 24 * 14)

        return JsonResponse({"status": True, "data": "/index/"})

    return JsonResponse({"status": False, "error": form.errors})
示例#9
0
def login_sms(request):
    """ 短信登录 """
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'login_sms.html', {'form': form})
    # POST
    form = LoginSMSForm(request.POST)
    if form.is_valid():
        # 用户输入正确,登录成功
        mobile_phone = form.cleaned_data['mobile_phone']

        # 把用户名写入到session中
        user_object = models.UserInfo.objects.filter(
            mobile_phone=mobile_phone).first()

        request.session['user_id'] = user_object.id
        request.session.set_expiry(60 * 60 * 24 * 14)  # 14天过期

        return JsonResponse({"status": True, 'data': "/index/"})

    return JsonResponse({"status": False, 'error': form.errors})
示例#10
0
def login_sms(request):
    """
    短信登录
    :param request:
    :return:
    """
    if request.method == 'GET':
        form = LoginSMSForm()
        return render(request, 'login_sms.html', {'form': form})

    form = LoginSMSForm(request.POST)
    if form.is_valid():
        # 用户输入正确,登录成功
        mobile_phone = form.cleaned_data['mobile_phone']
        # 将用户信息放入session
        user_object = models.UserInfo.objects.filter(mobile_phone=mobile_phone).first()

        request.session['user_id'] = user_object.id
        # request.session['user_name'] = user_object.username
        request.session.set_expiry(60 * 60 * 24 * 7)

        return JsonResponse({'status': True, 'data': "/index/"})
    return JsonResponse({'status': False, 'error': form.errors})