views.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. from django.shortcuts import render,redirect
  2. from .models import UserInfo
  3. def index(request):
  4. return render(request,'index.html')
  5. def login(request):
  6. if request.method != 'POST' :
  7. return render(request, 'login.html')
  8. else :
  9. user = request.POST.get('username')
  10. pwd = request.POST.get('pwd')
  11. typ = request.POST.get('n1')
  12. if user == '' :
  13. return redirect('index:none_user')
  14. elif pwd == '' :
  15. return redirect('index:none_pwd')
  16. elif typ != '0' and typ != '1' :
  17. return redirect('index:none_typ')
  18. user_list = UserInfo.objects.all()
  19. for info in user_list :
  20. if info.username == user :
  21. if info.password == pwd :
  22. if int(typ) == info.Type :
  23. if typ == '0' :
  24. iid = info.id
  25. return redirect('Users:hello',iid)
  26. else :
  27. return redirect('Sellers:sell-hello')
  28. elif info.Type == 0 or info.Type == 1 :
  29. return redirect('index:wro_typ')
  30. else :
  31. return redirect('index:can_not_login')
  32. else :
  33. return redirect('index:wro_pwd')
  34. return redirect('index:wro_user')
  35. def none_user (request) :
  36. return render(request,'none_user.html')
  37. def none_pwd (request) :
  38. return render(request,'none_pwd.html')
  39. def none_typ (request) :
  40. return render(request,'none_typ.html')
  41. def wro_typ (request) :
  42. return render(request,'wro_typ.html')
  43. def wro_pwd (request) :
  44. return render(request,'wro_pwd.html')
  45. def wro_user (request) :
  46. return render(request,'wro_user.html')
  47. def register(request):
  48. if request.method != 'POST' :
  49. return render(request,'register.html')
  50. else :
  51. user = request.POST.get('username')
  52. print(user)
  53. pwd = request.POST.get('pwd')
  54. apwd = request.POST.get('aga_pwd')
  55. name = request.POST.get('name')
  56. licen = request.POST.get('lic')
  57. licnum = request.POST.get('lic_num')
  58. sex = request.POST.get('n1')
  59. gra = request.POST.get('grand')
  60. phone = request.POST.get('pho_num')
  61. e_mal = request.POST.get('e_mail')
  62. all_num = phone.isdigit()
  63. right_num = ['139','138','137','136','134','135','147','150','151','152','157','158','159','172','178','182',
  64. '183','184','187','188','195','197','198','130','131','132','140','145','146','155','156','166',
  65. '185','186','175','176','196','133','149','153','177','173','180','181','189','191','193','199']
  66. 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',
  67. 'o','p','q','r','s','t','u','v','w','x','y','z','.','@','_','A','B','C','D','E','F','G','H','I',
  68. 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
  69. right_lic = ['1','2','3','4','5','6','7','8','9','0']
  70. vertify = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
  71. finall = ['1','0','X','9','8','7','6','5','4','3','2']
  72. wro_lic = False
  73. for lic in licnum[:17] :
  74. if lic not in right_lic:
  75. wro_lic = True
  76. At_num = 0
  77. wro_bit = False
  78. for bit in e_mal :
  79. if bit == '@' :
  80. At_num = At_num+1
  81. if bit not in right_bit :
  82. wro_bit = True
  83. users = UserInfo.objects.all()
  84. registered = False
  85. for User in users :
  86. if User.name == name :
  87. registered = True
  88. if user == '' :
  89. return redirect('index:non_user')
  90. if pwd == '' :
  91. return redirect('index:non_pwd')
  92. if len(pwd) < 6 :
  93. return redirect('index:short_pwd')
  94. if len(pwd) > 16 :
  95. return redirect('index:long_pwd')
  96. if apwd == '' :
  97. return redirect('index:non_apwd')
  98. if pwd != apwd :
  99. return redirect('index:not_equ')
  100. if name == '' :
  101. return redirect('index:non_name')
  102. if registered == True :
  103. return redirect('index:registered')
  104. if licen == '0' :
  105. return redirect('index:non_lic')
  106. if licnum == '' :
  107. return redirect('index:non_licnum')
  108. if licen == '1' :
  109. if len(licnum) !=18 or wro_lic == True :
  110. return redirect('index:wro_licnum')
  111. sum = 0
  112. i = 0
  113. for num in licnum [:17] :
  114. a = int(num) * vertify[i]
  115. sum = sum + a
  116. i = i+1
  117. vert = sum % 11
  118. if finall[vert] != licnum[-1] :
  119. return redirect('index:wro_licnum')
  120. if sex != '1' and sex != '2' :
  121. return redirect('index:non_sex')
  122. if gra == '0' :
  123. return redirect('index:non_gra')
  124. if phone == '' :
  125. return redirect('index:non_pho')
  126. if len(phone) !=11 or all_num == False or phone[:3] not in right_num:
  127. return redirect('index:wro_phone')
  128. if e_mal == '' :
  129. return redirect('index:non_ema')
  130. if At_num != 1 or wro_bit == True or e_mal[-4:] != '.com' :
  131. return redirect('index:wro_mail')
  132. UserInfo.objects.create(username=user, password=pwd, name=name, licence=licen, lic_num=licnum, sex=sex,
  133. grand=gra, phone=phone, mail=e_mal)
  134. return redirect('index:login')
  135. def non_user (request) :
  136. return render(request,'non_user.html')
  137. def non_pwd (request) :
  138. return render(request,'non_pwd.html')
  139. def non_apwd (request) :
  140. return render(request,'non_apwd.html')
  141. def not_equ (request) :
  142. return render(request,'not_equ.html')
  143. def non_name (request) :
  144. return render(request,'non_name.html')
  145. def non_lic (request) :
  146. return render(request,'non_lic.html')
  147. def non_licnum (request) :
  148. return render(request,'non_licnum.html')
  149. def non_sex (request) :
  150. return render(request,'non_sex.html')
  151. def non_gra (request) :
  152. return render(request,'non_gra.html')
  153. def non_pho (request) :
  154. return render(request,'non_pho.html')
  155. def non_ema (request) :
  156. return render(request,'non_ema.html')
  157. def can_not_login (request) :
  158. return render(request,'can_not_login.html')
  159. def short_pwd (request) :
  160. return render(request,'short_pwd.html')
  161. def long_pwd (request) :
  162. return render(request,'long_pwd.html')
  163. def wro_phone (request) :
  164. return render(request,'wro_phone.html')
  165. def wro_mail (request) :
  166. return render(request,'wro_mail.html')
  167. def registered (request) :
  168. return render(request,'registered.html')
  169. def wro_licnum (request):
  170. return render(request,'wro_licnum.html')
  171. # Create your views here.