Authentication

User Registration

  • Password provision and confirmation

    • Define additional columns in UserCreationForm

    • Check if they match in save logic

  • Encrypted password storage

    • User.objects.create_user(username, email=None, password=None)

    • user.set_password(password)

Login

Is the user a logged in person?

Stateless & Connectionless

  • Each request is an independent event

    • cookie connects this!

User Object

User Object Hierarchy

  • AbstractBaseUser

  • AbstractUser

  • User

User Model

Primary attributes of default user

  • username

  • password

  • email

  • first_name

  • last_name

Creating Users

Changing Password

1. Using command line

2. Using set_password()

Authenticating Users

authenticate(request=None, **credentials)

  • use it to verify a set of credentials

  • takes credentials as keyword arguments

    • username and password for the default cases

  • returns User object if credentials are valid for a backend

Shopping Cart

  1. User ---> Shopping Cart ---> Coupang

  2. User <--- Cookie <--- Coupang

  • Shopping Cart == cookie

  • Purchase History == data

Login == create

Logout == delete

Login Form

  • AuthenticationForm is not a ModelForm but just a Form!

Login Function

  • Filter POST first with the first if to handle else statement smoothly

    • why?

      • If you filter GET first, when POST doesn't pass .is_valid() and falls to else, you have to write code to render again!

      • That is, use POST first for code economy!

+

Reason for branching POST first

  1. Code conciseness

  2. REST API support

  • Currently we only support GET & POST, but when configuring methods RESTfully later, multiple methods like GET/POST/PUT/DELETE will come, and handling GET method at the end allows for the most concise code configuration!

Message Framework

new

-> Post writing page (form)

create

-> Save to DB

-> render

-> redirect(success status)

-> redirect('articles:index')

HTTP is a repetition of request and response!

HTTP

  • stateless

    • Once a request is sent, the state (past) cannot be known

    • All requests & responses are one-time

    • HTTP is a disconnected protocol

  • connectionless

Message Framework

  • It's meaningful to pass the previous state to the next Request & Response

    • Fallback Storage

      • If Cookie doesn't work, use Session

Dynamic view

Article CRUD

  • title, content, created_at, updated_at

User CRUD (Manual < Django)

+

  • in memory cache -> Think of it as cache loaded into ram

    • memcached

    • redis

  • Google ad ID......gdpr

  • macaddress = device information

Last updated