python manage.py startapp pincode_auth_app
# pincode_auth_app/models.py from django.contrib.auth.models import
AbstractUser from django.db import models class CustomUser(AbstractUser):
pin_code = models.CharField(max_length=4, blank=True, null=True)
***************
# pincode_auth_app/admin.py from django.contrib import admin from .models
import CustomUser
admin.site.register(CustomUser)
***********************
python manage.py makemigrations
python manage.py migrate
********************************
# pincode_auth_app/forms.py from django import forms class
PinCodeLoginForm(forms.Form):
username = forms.CharField(max_length=150)
pin_code = forms.CharField(max_length=4, widget=forms.PasswordInput)
*********************************
# pincode_auth_app/views.py from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login from .forms import
PinCodeLoginForm def pin_code_login(request): if request.method == 'POST':
form = PinCodeLoginForm(request.POST) if form.is_valid(): username =
form.cleaned_data['username'] pin_code = form.cleaned_data['pin_code'] user
= authenticate(request, username=username, pin_code=pin_code) if user is not
None: login(request, user) return redirect('success_page') # Redirect to a
success page else: # Authentication failed return render(request,
'login.html', {'form': form, 'error': 'Invalid username or pin code'}) else:
form = PinCodeLoginForm()
return render(request, 'login.html', {'form': form})
*************************************
<!-- pincode_auth_app/templates/login.html --> <!DOCTYPE html> <html> <head>
<title>Pin Code Login</title> </head> <body> <h2>Login</h2> {% if error %} <
p style="color: red;">{{ error }}</p> {% endif %} <form method="post" action
="{% url 'pin_code_login' %}"> {% csrf_token %} {{ form.as_p }} <button type
="submit">Login</button> </form> </body>
</html>
*******************************
  # pincode_auth/urls.py from django.urls import path from
pincode_auth_app.views import pin_code_login urlpatterns = [ path(
'pin-code-login/', pin_code_login, name='pin_code_login'), # Add other URLs
as needed ]
*******************************************
# pincode_auth/urls.py from django.contrib import admin from django.urls
import path, include urlpatterns = [ path('admin/', admin.site.urls), path(
'', include('pincode_auth_app.urls')),
]


On Tue, Jan 16, 2024 at 8:02 PM ABDUL HAFEEZ <[email protected]> wrote:

> example:
> I have a model with fields username and password
> when users create account  there credentials saved in db next I want that 
> *instead
> of login with password I want create token *so he can login with token
> not password
>
> what should I do
> please provide me logic steps if someone have done already
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e43d49a3-e950-4396-9f90-3b1cd6f7af0an%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/e43d49a3-e950-4396-9f90-3b1cd6f7af0an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGAxPTyJC0x31Yr%2Bu7u4qfwmeqcsv-Z6TUW0nA6ctivUXD6jdw%40mail.gmail.com.

Reply via email to