123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- from django.shortcuts import render,redirect
- from .models import UserInfo
- def index(request):
- return render(request,'index.html')
- def login(request):
- if request.method != 'POST' :
- return render(request, 'login.html')
- else :
- user = request.POST.get('username')
- pwd = request.POST.get('pwd')
- typ = request.POST.get('n1')
- if user == '' :
- return redirect('index:none_user')
- elif pwd == '' :
- return redirect('index:none_pwd')
- elif typ != '0' and typ != '1' :
- return redirect('index:none_typ')
- user_list = UserInfo.objects.all()
- for info in user_list :
- if info.username == user :
- if info.password == pwd :
- if int(typ) == info.Type :
- if typ == '0' :
- iid = info.id
- return redirect('Users:hello',iid)
- else :
- return redirect('Sellers:sell-hello')
- elif info.Type == 0 or info.Type == 1 :
- return redirect('index:wro_typ')
- else :
- return redirect('index:can_not_login')
- else :
- return redirect('index:wro_pwd')
- return redirect('index:wro_user')
- def none_user (request) :
- return render(request,'none_user.html')
- def none_pwd (request) :
- return render(request,'none_pwd.html')
- def none_typ (request) :
- return render(request,'none_typ.html')
- def wro_typ (request) :
- return render(request,'wro_typ.html')
- def wro_pwd (request) :
- return render(request,'wro_pwd.html')
- def wro_user (request) :
- return render(request,'wro_user.html')
- def register(request):
- if request.method != 'POST' :
- return render(request,'register.html')
- else :
- user = request.POST.get('username')
- print(user)
- pwd = request.POST.get('pwd')
- apwd = request.POST.get('aga_pwd')
- name = request.POST.get('name')
- licen = request.POST.get('lic')
- licnum = request.POST.get('lic_num')
- sex = request.POST.get('n1')
- gra = request.POST.get('grand')
- phone = request.POST.get('pho_num')
- e_mal = request.POST.get('e_mail')
- all_num = phone.isdigit()
- right_num = ['139','138','137','136','134','135','147','150','151','152','157','158','159','172','178','182',
- '183','184','187','188','195','197','198','130','131','132','140','145','146','155','156','166',
- '185','186','175','176','196','133','149','153','177','173','180','181','189','191','193','199']
- right_bit = ['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n',
- 'o','p','q','r','s','t','u','v','w','x','y','z','.','@','_','A','B','C','D','E','F','G','H','I',
- 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
- right_lic = ['1','2','3','4','5','6','7','8','9','0']
- vertify = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
- finall = ['1','0','X','9','8','7','6','5','4','3','2']
- wro_lic = False
- for lic in licnum[:17] :
- if lic not in right_lic:
- wro_lic = True
- At_num = 0
- wro_bit = False
- for bit in e_mal :
- if bit == '@' :
- At_num = At_num+1
- if bit not in right_bit :
- wro_bit = True
- users = UserInfo.objects.all()
- registered = False
- for User in users :
- if User.name == name :
- registered = True
- if user == '' :
- return redirect('index:non_user')
- if pwd == '' :
- return redirect('index:non_pwd')
- if len(pwd) < 6 :
- return redirect('index:short_pwd')
- if len(pwd) > 16 :
- return redirect('index:long_pwd')
- if apwd == '' :
- return redirect('index:non_apwd')
- if pwd != apwd :
- return redirect('index:not_equ')
- if name == '' :
- return redirect('index:non_name')
- if registered == True :
- return redirect('index:registered')
- if licen == '0' :
- return redirect('index:non_lic')
- if licnum == '' :
- return redirect('index:non_licnum')
- if licen == '1' :
- if len(licnum) !=18 or wro_lic == True :
- return redirect('index:wro_licnum')
- sum = 0
- i = 0
- for num in licnum [:17] :
- a = int(num) * vertify[i]
- sum = sum + a
- i = i+1
- vert = sum % 11
- if finall[vert] != licnum[-1] :
- return redirect('index:wro_licnum')
- if sex != '1' and sex != '2' :
- return redirect('index:non_sex')
- if gra == '0' :
- return redirect('index:non_gra')
- if phone == '' :
- return redirect('index:non_pho')
- if len(phone) !=11 or all_num == False or phone[:3] not in right_num:
- return redirect('index:wro_phone')
- if e_mal == '' :
- return redirect('index:non_ema')
- if At_num != 1 or wro_bit == True or e_mal[-4:] != '.com' :
- return redirect('index:wro_mail')
- UserInfo.objects.create(username=user, password=pwd, name=name, licence=licen, lic_num=licnum, sex=sex,
- grand=gra, phone=phone, mail=e_mal)
- return redirect('index:login')
- def non_user (request) :
- return render(request,'non_user.html')
- def non_pwd (request) :
- return render(request,'non_pwd.html')
- def non_apwd (request) :
- return render(request,'non_apwd.html')
- def not_equ (request) :
- return render(request,'not_equ.html')
- def non_name (request) :
- return render(request,'non_name.html')
- def non_lic (request) :
- return render(request,'non_lic.html')
- def non_licnum (request) :
- return render(request,'non_licnum.html')
- def non_sex (request) :
- return render(request,'non_sex.html')
- def non_gra (request) :
- return render(request,'non_gra.html')
- def non_pho (request) :
- return render(request,'non_pho.html')
- def non_ema (request) :
- return render(request,'non_ema.html')
- def can_not_login (request) :
- return render(request,'can_not_login.html')
- def short_pwd (request) :
- return render(request,'short_pwd.html')
- def long_pwd (request) :
- return render(request,'long_pwd.html')
- def wro_phone (request) :
- return render(request,'wro_phone.html')
- def wro_mail (request) :
- return render(request,'wro_mail.html')
- def registered (request) :
- return render(request,'registered.html')
- def wro_licnum (request):
- return render(request,'wro_licnum.html')
- # Create your views here.
|