当前位置:网站首页>Project login and registration ideas
Project login and registration ideas
2022-07-27 05:38:00 【Csdn__ F】
redis
Main knowledge points
string Type of addition, deletion, modification and query
purpose : Verification code storage uuid Corresponding to the verification code text
increase : set
Delete del set Set up ex Number of seconds
Change set
check get
list Type of addition, deletion, modification and query
Historical record
increase : lpush rpush
Delete del Clear the entire list lrem key count rem
Change Is not the point You can use delete first , Add
check lrange key 0 -1
set Type of addition, deletion, modification and query
Collection
increase : sadd
Delete del Clear the entire list srem key value
Change There is no need to change , It's ok if you don't delete it
check smembers key
hash Type of addition, deletion, modification and query
The shopping cart
increase : hset key key value
Delete del Clear the entire list hdel key key
Change hset key key value
check hgetall
register
front end
check
stay input above , To bind events and data v-model
<input @blur="checkUser" v-model="username" /> If you find that input You can't input anything ,v-model What's inside , Not in the data It is defined- @click=“ Function names are not bracketed ” Click event When you submit your registration , When submitting login , Generally, it is bound on the button
- @blur=“ Function name ” Loss of focus event Usually in input Bound above . What is losing focus , Is the cursor from input Move it out
stay js Of methods Inside , Define a function , The function name is the function name written in the event
data(){ return { "username":"", // If you don't write this , you input Enter something that doesn't go in } } ,methods:{ Function name (){ xxxx The body of the function // Want to get username var uname = this.username // send out axios Just ask } }
Verification Code
<img :src="img_path" @click="ver_img" /> Colon can't be less , There is a function
import {
v4 as uuid4} from 'uuid'
data:{
img_path:"",
},
create(){
this.ver_img() # After the page is loaded , Do it now
},
methods:{
ver_img(){
uuid = uuid4() # Generate a uuid
this.img_path = "/user/ver_img/" + uuid + "/"
}
}
register
- to button Button binding click event ,
- Implementation function , send out axios request ,post request
- post With parameters ,post(url, Parameters )
- The parameter is a dictionary format { “username”:this.username,“pwd”:this.password }
Back end
check
Get the data from the front desk get/post
- Usually in class , We use get+ Dynamic routing , Parameters are passed by route
- get The ginseng , The parameters are directly in url above ,request.query_params.get(),
- post The ginseng , stay request.data.get() Inside
- Route parameters , When you accept it ,def get(self,request, Parameters ) The parameter name must be the same as The name in the route is the same .
check
Uniqueness check
- Go to the database to query this data
def get(self,request,uname): user_info = User.objects.filter(username=uname).first() if user_info: # Return existence else: # If there is judgment in the future , You don't have to write it else # Return to availableformat checks
- Define regular rule = r’’
- Regular matching
- Import re package import re
- matching Return value = re.findall( Regular variables , Variables to match strings )
- Determine the return value If it is false , Description does not match
- According to whether it matches , Return to the corresponding prompt
Generate verification code
- Get the message from the front desk UUID , To put it bluntly, it's a string
- Generate a 4 Random number of bits ,random.randint(1000,9999)
- Generated random number , Can't be used directly . the reason being that int type , Need to be converted to string type str()
- Turn random numbers into pictures captcha
- You have to match the verification code with uuid The corresponding relationship exists redis Inside
# Guide pack
from captcha.image import ImageCaptcha
from django.http import HttpResopnse
def get(self,request,uuid):
# The code is incomplete , Only the key things are written , Don't copy directly
# Instantiate the class of the verification code
img = ImageCaptcha()
# Generate , Call a generation method of the instantiated object
img_byte = img.generate( Random string ) # Parameters passed in , It must be of string type , If not , You need str Change my
# save uuid And random string
r = redis.Redis( Parameter omitted , Add according to your own conditions )
r.set(uuid, Random string ,ex=300)
# Returns the binary of the picture , You can't use Response
return HttpResopnse(img_byte,content_type="image/png") # This function , yes django Bring it with you
Verification code verification
- Get the parameters passed from the foreground uuid and code
- according to uuid Go to redis database , Find the corresponding value code_byte, The return value is one byte type , Need to be converted to string type
- link redis redis.Redis(host=“127.0.0.1”,port=6379,password=“123456”)
- hold redis Checked up , convert to string type code_str = code_byte.decode() # decode Will drift yellow , Normal phenomenon
- Judgment database code_str And user input code Is it consistent
- If the same , Verification passed , atypism , Verification failed
register
- Get the data from the front desk get/post
- request.data.get() obtain post
- Dynamic routing obtain get Dynamic routing is defined and you? def get When , perhaps post You need to receive this parameter
- Possible mistakes :
- The parameter name passed from the foreground is different from the parameter name accepted by your backend , The phenomenon is that after the accepted parameters are printed , Show None, Or it may report an error . A hint of None There is no xx attribute , Or the method . solve : After you get the parameters , Debug it right away .
- Add : Error resolution :
- 404 error , Find the slash and write it , Or is the routing configured , Or is the word wrong
- 500 error , Have you got the parameters , Is the code red 、 yellow . If you can't find it, just do it in a code block return Resopnse()
- Logic error returned , For example, the user is not logged in 、 Wrong password , There is something wrong with logical judgment . It is not necessarily to judge that there is a problem with this statement , It may be the value of your judgment , Have you got , Or there is a problem with the type . solve : you are here if Before judging , Put the conditions to be judged print come out , Take a look at .
- Check the parameters , Omitted in the lecture . Because when inputting before , It was checked once . It doesn't mean it's unnecessary , Just say , The code is repeated , No longer rewrite .
- It's best to judge whether the user name already exists
- Write to database
- Model .objects.create( Keyword parameters )
- Return response
- return Response() Pay attention to the import package
Sign in
front end
Back end
Get the data from the front desk , User name and password
According to the user name , Find this data , If this data doesn't exist at all , Just return the wrong user name or password .
If the data is found , Compare the passwords . if username == user_info.password:
If it's not consistent , Just return the wrong user name or password
If the same , Return to login successfully , It is not enough to prompt successful login , Also return the user's information
Basic information of users , There is user Back inside , The front desk display uses . user name 、 cell-phone number . Password cannot be returned
User authentication information , Your login credentials ( Payment receipt ).JWT
Generation is simple , Just one line of code
# pip install pyjwt import jwt from django.conf import settings payload = { "user_id":user_info.id, "user_name":user_info.name, } token = jwt.encode(payload,settings.SECRET_KEY,al...="HS256") # This line of code is the focus # payload It's actually user information , It's better to add one inside user_id # To use settings , To guide the package from django.conf import settings return Resopnse({ "code":"", "msg":"", "user":payload, "token":token, })
边栏推荐
猜你喜欢

Dnsmasq Usage Summary

pytorch安装新坑

Share a multiple-choice question about define (including the replacement rules, program environment and preprocessing related knowledge of define during precompiling)

Li Hongyi machine learning team learning punch in activity day04 - Introduction to deep learning and back propagation mechanism

Hi3516dv300 environment setup

Asynchronous data SMS verification code

C language elementary level -- branch statement (if, switch)

Redis publish subscribe mode

First knowledge of C language -- what is C language

Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
随机推荐
GCC 编译选项
JS中如何判断一个对象是空对象
[codeworks round 801 div2 D tree queries] tree greedy conclusion
块,行内块元素之间存在间隙
Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)
Day5 --- Flask-RESTful请求响应与SQLAlchemy基础
JS==操作符的强制类型转换规定
JS基础知识--每日学习总结①
cmd命令和npm命令
Flask请求数据获取与响应
Day4 --- Flask 蓝图与Rest-ful
C language string function: strlen, strcpy, strcat
【codeforces 1695C Zero Path】DP
set集合
时间复杂度与空间复杂度
2021 Niuke multi school training camp 5 (question b)
C WPF uses listbox to implement ruler control
Multiplication sorting in torch, * & torch. Mul () & torch. MV () & torch. Mm () & torch. Dot () & @ & torch. Mutmal ()
GCC compilation options
Introduction and management of heap memory in C language