Authentication

ํšŒ์› ๊ฐ€์ž…

  • ๋น„๋ฐ€๋ฒˆํ˜ธ ์ œ๊ณต ๋ฐ ํ™•์ธ

    • UserCreateionForm์ถ”๊ฐ€ column ์ •์˜

    • ์ €์žฅ logic์—์„œ ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธ

  • ๋น„๋ฐ€๋ฒˆํ˜ธ ์•”ํ˜ธํ™” ์ €์žฅ

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

    • user.set_password(password)

๋กœ๊ทธ์ธ

์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธ ํ•œ ์‚ฌ๋žŒ์ด๋‹ค?

Stateless & Connectless

  • ๋งค ์š”์ฒญ์ด ๋…๋ฆฝ ์‚ฌ๊ฑด

    • cookie๊ฐ€ ์ด๊ฑธ ์ด์–ด์ค€๋‹ค!

User Object

from django.contrib.auth.models import User
image-20200418162725783
  • AbstractBaseUser

  • AbstractUser

  • User

image-20200414200102509

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

์žฅ๋ฐ”๊ตฌ๋‹ˆ

  1. ์‚ฌ์šฉ์ž ---> ์žฅ๋ฐ”๊ตฌ๋‹ˆ ---> ์ฟ ํŒก

  2. ์‚ฌ์šฉ์ž <--- ์ฟ ํ‚ค <--- ์ฟ ํŒก

  3. ์žฅ๋ฐ”๊ตฌ๋‹ˆ == cookie

  4. ๊ตฌ๋งค๋‚ด์—ญ == data

๋กœ๊ทธ์ธ == create

๋กœ๊ทธ์•„์›ƒ == delete

๋กœ๊ทธ์ธ Form

  • AutehticationForm์€ ModelForm ์ด ์•„๋‹ˆ๋ผ ๊ทธ๋ƒฅ Form ์ด๋‹ค!

๋กœ๊ทธ์ธ ํ•จ์ˆ˜

  • else๋ฌธ ์ฒ˜๋ฆฌ๋ฅผ ๋งค๋„๋Ÿฝ๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์ฒซ๋ฒˆ์งธ if๋กœ POST๋ฅผ ๋จผ์ € ๊ฑฐ๋ฅธ๋‹ค

    • why?

      • ๋งŒ์•ฝ GET์„ ๋จผ์ € ๊ฑฐ๋ฅด๋ฉด, POST์—์„œ .is_valid()์— ๊ฑธ๋ฆฌ์ง€ ์•Š๊ณ  else ๋กœ ๋–จ์–ด์ง€๋ฉด ๋‹ค์‹œ renderํ•˜๋Š” ์ฝ”๋“œ ์จ์ค˜์•ผํ•ด์„œ!

      • ์ฆ‰, code์˜ ๊ฒฝ์ œ์„ฑ์„ ์œ„ํ•ด *POST ๋ฅผ ๋จผ์ € ์“ด๋‹ค!

+

POST ๋กœ ๋จผ์ € ๋ถ„๊ธฐํ•˜๋Š” ์ด์œ 

  1. ์ฝ”๋“œ์˜ ๊ฐ„๊ฒฐ์„ฑ

  2. REST API ๋Œ€์‘

    • ํ˜„์žฌ ์šฐ๋ฆฌ๋Š” GET & POST๋งŒ ๋Œ€์‘ํ•˜๊ณ  ์žˆ๋Š”๋ฐ ์ดํ›„์— RESTful ํ•˜๊ฒŒ ๋ฉ”์†Œ๋“œ ๊ตฌ์„ฑํ•  ๊ฒฝ์šฐ GET/POST/PUT/DELETE ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฉ”์†Œ๋“œ๊ฐ€ ์˜ค๊ฒŒ ๋˜๊ณ  GET method๊ฐ€ ๋งˆ์ง€๋ง‰์—์— ํ•ธ๋“ค๋ง๋˜๋Š” ํ˜•ํƒœ๊ฐ€ ๊ฐ€์žฅ ๊ฐ„๊ฒฐํ•œ ์ฝ”๋“œ ๊ตฌ์„ฑ์ด ๊ฐ€๋Šฅ!

Message Framework

new

-> ๊ธ€ ์ž‘์„ฑ ํŽ˜์ด์ง€ (form)

create

-> DB์—์ €์žฅ

-> render

-> redirect(์„ฑ๊ณต์—ฌ๋ถ€)

-> redirect('articles:index')

HTTP๋Š” request์™€ response์˜ ๋ฐ˜๋ณต์ด๋‹ค!

HTTP

  • stateless (๋ฌด ์ƒํƒœ์„ฑ)

    • ํ•œ๋ฒˆ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด ์ƒํƒœ(๊ณผ๊ฑฐ)๋ฅผ ์•Œ ์ˆ˜ ์—†์Œ

    • ๋ชจ๋“  ์š”์ฒญ & ์‘๋‹ต์€ ์ผํšŒ์„ฑ์ด๋‹ค

    • HTTP๋Š” ๋‹จ์ ˆ์ ์ธ protocol

  • connectionless (๋ฌด ์—ฐ๊ฒฐ์„ฑ)

Message Framework

  • ์ด์ „์˜ ์ƒํƒœ๋ฅผ ๋‹ค์Œ Request & Response์— ๋„˜๊ฒจ์ค€๋‹ค๋Š” ๊ฒƒ์ด ์˜๋ฏธ๊ฐ€ ์žˆ๋‹ค

    • Fallback Storage

      • Cookie ๊ฐ€ ์•ˆ๋˜๋ฉด Session

Dynamic view

Article CRUD

  • title, content, create_at, updated_at

User CRUD (์ง์ ‘ < Django)

+

  • in memory cache -> ram์— ๋„์›Œ๋†“๋Š” cache๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋จ

    • memcached

    • redis

  • ๊ตฌ๊ธ€ ๊ด‘๊ณ  ์•„์ด๋””......gdpr

  • macaddress = ๊ธฐ๊ธฐ์ •๋ณด

Last updated

Was this helpful?