A user logs out

First, the functional requirements analysis

  1. Log in functional analysis

    1.1 Login Process

    1.2 function (a function of a request)

     ~ Login page

     ~ Login feature

     ~ Logout function

Second, the login page

  1. Interface Design

    1.1. Interface Description

    Category Description

    GET request method

    url defined / usel / login /

    No parameter format parameters

    1.2 returns the result

    log in page

    1.3 code implementation

Third, the login feature

  1. Business Process

    1.1 calibration parameters

      ~ 1. Accounts check

      ~ 2. Cryptographic checksum

      1-3. Joint checking account password

    1.2 Login logic

      ~ 1. Saved state of the session

      1-2. According Remember Me option, a period setting (session_id)

  2. Interface Design

    2.1. Interface Description

    Category Description

    GET request method

    url defined / usel / login /

    Parameter format form

    2.2 Parameter Description

    You must describe whether parameters type

    string account is an account (phone number or user name) entered by the user

    user password entered is the password string

    Check whether remember string no user login-free

    2.3 returns the result

    {

    error: '0'

    errmsg: 'ok'

    }

    2.4 Code

user/views.py

 

the LoginView class (View): 
"" "
login view
URL: '/ User / Login /'
" ""
DEF GET (Self, Request):
return the render (Request, 'User / the login.html')

DEF POST (Self, Request ):
# 1 first checksum.
form the LoginForm = (of request.POST)
IF form.is_valid ():
. # 2 and log
return json_response (errmsg = 'Congratulations to login')
the else:
# the error message spliced forms
err_msg_list = []
for form.errors.values in Item ():
err_msg_list.append (Item [0])

err_msg_str = '/'.join(err_msg_list)
return json_response (errno = Code.PARAMERR, errmsg=err_msg_str)

user/forms.py

 

Fourth, the logout function

  1. Interface Design

  Interface Description

  Category Description

  GET request method

  url defined / user / logout /

  No parameter format parameters

 

  2. The back-end code

 

    

 

    

  

 

Guess you like

Origin www.cnblogs.com/wdty/p/11348893.html