Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Django注册期间验证otp?_Python_Django_Django Models_Django Views - Fatal编程技术网

Python 如何在Django注册期间验证otp?

Python 如何在Django注册期间验证otp?,python,django,django-models,django-views,Python,Django,Django Models,Django Views,我试图在用户注册期间在Django中进行基于OTP的身份验证,但我不知道如何将电子邮件从注册页面传递到OTP页面并在模型中编辑值 注册方法工作正常,但我不知道如何将用户_状态更新为“v”,即在otp验证后注册的特定电子邮件的验证 视图.py def signup(request): if request.method == 'GET': return render(request,'registration/signup.html') else:

我试图在用户注册期间在Django中进行基于OTP的身份验证,但我不知道如何将电子邮件从注册页面传递到OTP页面并在模型中编辑值

注册方法工作正常,但我不知道如何将用户_状态更新为“v”,即在otp验证后注册的特定电子邮件的验证

视图.py

def signup(request):
    if request.method == 'GET':
        return render(request,'registration/signup.html')
    else:
        postData = request.POST
        first_name = postData.get('firstname')
        last_name = postData.get('lastname')
        email = postData.get('email')
        username = postData.get('username')
        phone = postData.get('phone')
        password = postData.get('password')
        #validation
        value = {'first_name':first_name,'last_name':last_name,'email':email,'username':username,'phone':phone}
        error_message = None
        if(not first_name):
            error_message="First Name Required"
        elif(not last_name):
            error_message="Last Name Required"
        elif(not email):
            error_message="Email is Required"
        elif(not username):
            error_message="Username is Required"
        elif(not phone):
            error_message="Phone Number is Required"
        elif len(phone) is not 10:
            error_message="Mobile Number is Invalid"
        elif(not password):
            error_message="Password is Required"
        elif len(password) < 6:
            error_message = 'Password must be 6 char long'
        #saving
        if not error_message:
            print(first_name,last_name,email,username,phone,password)
            customer = Customer(first_name=first_name,last_name=last_name,email=email,username=username,password=password,phone=phone)
            customer.register()
            return render(request,'registration/otp.html')
        else:
            data = {
                'error' : error_message,
                'values' : value 
                }
            return render(request,'registration/signup.html',data)

def otp(request):
    if request.method == 'GET':
        return render(request,'registration/otp.html')
    else:
        otp_gen = None
        postData = request.POST
        otp_enter = postData.get(otp_enter)
        otp_gen = random.randint(10000,99999)
        print(otp_gen)
        otp_message = None
        if(not otp_enter):
            otp_message="Please enter OTP"
        elif otp_enter is not otp_gen:
            otp_message ="Incorrect OTP"
        if not otp_message:
            customer = Customer.objects.get(email=email)
            customer.user_status = 'v'
            customer.save() 
            return render(request,'registration/login.html')

class Customer(models.Model):
    USER_STATUS = (
        ('nv',"Not Verified"),
        ('v',"Verified"),
        ('sp',"Account Suspended")
    )
    MERCHANT_STATUS = (
        ('m',"Merchant"),
        ('nm',"Non Merchant")
    )
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50) 
    email = models.EmailField()
    username = models.CharField(max_length=20)
    password = models.CharField(max_length=20)
    phone = models.CharField(max_length=15)
    user_type = models.CharField(
        max_length=10,
        choices=MERCHANT_STATUS,
        default='nm'
    )
    user_status = models.CharField(
        max_length=10,
        choices=USER_STATUS,
        default='nv'
    )
    joined_on = models.DateTimeField(auto_now_add=True)
    
    def register(self):
        self.save()
otp.html

{% extends "base_1.html" %}
{% block content %}
<div class="container">
  <div class="p-4 m-4">
    <div class="col-lg-5 mx-auto border rounded pb-3 pt-3">
      <h3 class="alert alert mx-auto"> Employees Signup</h3>
<form action="/otp" method="POST">
  {% csrf_token %}

  {% if error %}
  <div class="alert alert-danger" role="alert">
    {{error}}
  </div>
  {% endif %}
  <div class="form-group">
    <label for="">Enter OTP sent on your Email</label>
    <input type="text" name="otp_enter" class="form-control" placeholder="Enter 5 digit OTP">
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
{% endblock %}
{%extensed“base_1.html”%}
{%block content%}
员工注册
{%csrf_令牌%}
{%if错误%}
{{error}}
{%endif%}
输入电子邮件中发送的OTP
提交
{%endblock%}