как проверить пользователя при регистрации с помощью мобильного otp в django? - PullRequest
0 голосов
/ 18 февраля 2020

my urls.py '' '

from django.urls import path, include
from . import views
urlpatterns = [
    path('enter_otp',views.otp_call,name='otp_confirmed')    
]'''

my views.py

' ''

def signup(request):
    if request.method == 'POST':
        username = request.POST["username"]
        last_name = request.POST["last_name"]
        first_name = request.POST["first_name"]
        date_of_birth = request.POST["birthday"]
        email = request.POST["email"]
        password = request.POST["password"]
        Phone = request.POST["phone"]
        gender = request.POST["gender"]
        if User.objects.filter(username=username).exists():
            messages.info(request,'username already taken')
            return render(request,"signup.html")
        if User.objects.filter(phone_no=Phone).exists():
            messages.error(request,'Phone number already in use')
            return render(request,"signup.html")
        else:
            sent = otp()
            print(sent)
            return otp_call(un=username,pswrd= password,mail = email, fn=first_name,ln=last_name,pn=Phone,dob=date_of_birth,gen=gender,otp=sent)
    else:
        return render(request,"signup.html")


def otp_call(request,**kwargs):
    if request.method == 'POST':
        trials = 0
        while trials<3:
            input_otp= request.POST["six_digit"]
            if input_otp == otp:
                signedup_user = User.objects.create_user(
                    username=un,
                    password=pswrd,
                    email=mail,
                    first_name=fn,
                    last_name =ln,
                    phone_no=pn,
                    date_of_birth=dob,
                    gender= gen
                )
                signedup_user.save()
                break
                return redirect('login')       
            if input_otp != otp:
                trials+=1
                messages.error(request,"wrong otp")
                return render(request,'otp_recieve.html')
    else: 
        return render(request,'otp_recieve.html')

'' '

У меня есть html, чтобы подтвердить otp с помощью post post и csrf_token, но я знаю, что это не правильный путь, потому что Urls.py тоже будет нуждаться в параметрах, как я могу проверить пользователей, использующих otp через мобильный и otp () в регистрации ( ) просто случайный генератор ключей 6 ди git, пожалуйста, помогите мне

1 Ответ

0 голосов
/ 18 февраля 2020

Вы можете отправить сгенерированный otp вашему бэкэнду в теле запроса в качестве полезной нагрузки от внешнего интерфейса. Вы можете написать ajax вызов, чтобы сделать это

Затем двое получат доступ к данным из резервной копии, просто

import requests
otp=req['otp']
...