SoFunction
Updated on 2024-10-29

Django Auth user authentication component implementation code

User Authentication Component.

Function: Record login authentication status with session

Prerequisites: user table: django comes with auth-user

python3 createsuperuser #create superuser

Supplementary anonymous users:

API:
  from  import auth :
    1. #if Validation succeeds return user object, otherwise return None
    user = (username=user,password=pwd)
    2. (request,user) # Currently logged in objects
    3. (request)
    from  import User #User == auth_user
    4. .is_authenticated
     = .create_user(username='',password='',email='')

  replenishment:
    anonymous user object (computing):
      anonymous user
      class 

       # This class implements the
      pretext,But there are a few differences.:
      idneverthelessNone
      usernameAlways empty string
      get_username()Always returns the empty string
      is_staffcap (a poem)is_superuserneverthelessFalse
      is_activeneverthelessFalse
      groupscap (a poem)user_permissionsForever empty.
      is_annonymous()come (or go) backTrue rather thanFalse
      is_authenticated()come (or go) back时False,rather thanTrue
      set_password()、check_password()、save()cap (a poem)delete()causeNotImplementedError。
      New in Django 1.8:
      additional AnonymouseUser.get_username()To better summarize the simulation:if not :(request,user) = AnonymousUser()else:==The login object is a global variable

This is the entire content of this article.