Когда я пытаюсь войти в систему, используя номер телефона, пароль и otp, он продолжает отображать страницу с номером телефона или выдает ошибку
``из django.shortcuts import render, redirect from django.contrib.auth import authenticate ,login from .models import Profile from django.contrib.auth.models import User from .mixins import MessageHandler import random
def Signup_page(request):
if request.method == "POST":
username = request.POST.get('username')
email = request.POST.get('email')
phone_number = request.POST.get('phone_number')
password = request.POST.get('password')
if User.objects.filter(email=email).exists():
return render(request, "sign_up.html", {'error': 'Email already in use'})
if Profile.objects.filter(phone_number=phone_number).exists():
return render(request, "sign_up.html", {'error': 'Phone number already in use'})
user = User.objects.create_user(username=username, email=email)
user.set_password( password)
user.save()
profile = Profile.objects.create(user=user, phone_number=phone_number)
profile.save()
return redirect('/login/')
return render(request, "sign_up.html")
def Login_page(request):
if request.method == "POST":
phone_number = request.POST.get('phone_number')
try:
profile = Profile.objects.get(phone_number=phone_number)
return redirect('/password/')
except Profile.DoesNotExist:
return render(request, "login.html", {'error': 'Phone number not found'})
return render(request, "login.html")
def password_page(request):
if request.method == "POST":
password = request.POST.get('password')
phone_number = request.POST.get('phone_number')
user = Profile. objects.get(phone_number = phone_number, password = password)
profile = Profile.objeects(user=user)
if user is not None:
profile.otp = random.randint(100000, 999999)
profile.save()
messagehandler = MessageHandler(profile.phone_number, profile.otp).send_otp_on_phone()
return redirect(f'/otp/<uid>/{profile.uid}')
else:
print('password check failed')
print("Rendering password.html")
return render(request, 'password.html')
def Otp_page(request , uid):
if request.method == "POST":
otp = request.POST.get('otp')
profile = Profile.objects.get(uid=uid)
if otp == profile.otp:
login(request,profile.user)
return redirect('/dashboard/')
def Dashboard_page(request):
return render(request, "dashboard.html")
`
я хочу, чтобы он мог перейти на страницу otp и отправить otp`