def superusermessage(request): if SessionManager.isLogouted(request): return HttpResponseRedirect("/login/") if not SessionManager.isAdministrator(request): return HttpResponseRedirect("/") user_list = models.PersonalInformation.objects.all() return render(request, 'vipmessage.html', locals())
def moremessage(request, user): if SessionManager.isLogouted(request): return HttpResponseRedirect("/login/") if not SessionManager.isAdministrator(request): return HttpResponseRedirect("/") user_list = models.PersonalInformation.objects.filter(username=user) #return HttpResponse(user) return render(request, 'moremessage.html', locals())
def forgetPasswordLogin(request): if SessionManager.isAdministrator(request): return HttpResponse("管理员禁止使用修改密码功能") #不修改 if request.method == 'POST': usernameForm = UsernameForm(request.POST) if usernameForm.is_valid(): username = FormsManager.getData(usernameForm, 'username') user = UserDB.objects.get(username=username) if user.isAdministrator(): return HttpResponse("管理员禁止使用修改密码功能") SessionManager.setUsername(request, username) return HttpResponseRedirect('/forgetpassword/') else: usernameForm = UsernameForm() return render(request, 'forgetPasswordUI.html', locals())
def customercourse(request): # 向页面输出当前用户已支付的订单信息 username = SessionManager.getUsername(request) #获取当前登录的用户名字 user = BuyRecord.objects.filter(username=username, pay_flag=True, valid=True) #获取当前用户已经支付的课程信息 return render(request, 'customercourseUI.html', {'order': user}) # 渲染页面 按照课程名排序
def completeinformation(request): #用户点击提交完善的个人信息 if request.method == 'POST': # 如果请求为表单提交 completeForm = CompleteForm(request.POST) # 获取表单内容 if completeForm.is_valid(): # 解析表单 name = FormsManager.getData(completeForm, 'name') age = FormsManager.getData(completeForm, 'age') profession = FormsManager.getData(completeForm, 'profession') phoneNumber = FormsManager.getData(completeForm, 'phoneNumber') sex = FormsManager.getData(completeForm, 'sex') birthday = FormsManager.getData(completeForm, 'birthday') height = FormsManager.getData(completeForm, 'height') weight = FormsManager.getData(completeForm, 'weight') bust = FormsManager.getData(completeForm, 'bust') waistline = FormsManager.getData(completeForm, 'waistline') hipline = FormsManager.getData(completeForm, 'hipline') shoulderwidth = FormsManager.getData(completeForm, 'shoulderwidth') #判断数据是否正确 #正确过后写数据库 username = SessionManager.getUsername(request) personalInformation = PersonalInformationDB.objects.get( username=username) personalInformation.setName(name) personalInformation.setAge(age) personalInformation.setProfession(profession) personalInformation.setPhoneNumber(phoneNumber) personalInformation.setSex(sex) personalInformation.setBirthday(birthday) personalInformation.setHeight(height) personalInformation.setWeight(weight) personalInformation.setBust(bust) personalInformation.setWaistline(waistline) personalInformation.setHipline(hipline) personalInformation.setShoulderwidth(shoulderwidth) return HttpResponseRedirect("/customerloginedindex/") # 跳转登陆后首页 else: usernamedd = SessionManager.getUsername(request) userid = PersonalInformationDB.objects.filter(username=usernamedd) if userid: completeForm = CompleteForm(instance=userid[0]) else: completeForm = CompleteForm() # 创建表单 return render(request, 'completeinformationUI.html', locals()) # 渲染页面
def login(request): # 用户登录功能视图函数 if request.method == 'POST': # 如果请求为表单提交 loginForm = LoginForm(request.POST) # 获取表单内容 if loginForm.is_valid(): # 解析表单 username = FormsManager.getData(loginForm, 'username') password = FormsManager.getData(loginForm, 'password') user = Customer.objects.get(username=username) # 尝试查询该用户 SessionManager.setLogin(request, username, user.isAdministrator()) if SessionManager.isAdministrator(request): return HttpResponseRedirect("/administratorloginedindex/") else: return HttpResponseRedirect("/customerloginedindex/") else: # 如果是普通访问(GET方法) if SessionManager.isLogined(request): return HttpResponseRedirect('/') # 如果已经登录,跳转到首页 else: loginForm = LoginForm() # 创建表单 return render(request, 'loginUI.html', locals()) # 渲染页面
def forgetPassword(request): if SessionManager.isAdministrator(request): return HttpResponse("管理员禁止使用修改密码功能") #不修改 if SessionManager.getUsername(request) is None: return HttpResponseRedirect("/forgetpasswordlogin/") #如果method是post(发布 if request.method == 'POST': forgetPasswordForm = ForgetPasswordForm(request.POST) #如果更改密码 有效 if forgetPasswordForm.is_valid(): username = SessionManager.getUsername(request) newPassword = FormsManager.getData(forgetPasswordForm, 'newPassword') user = UserDB.objects.get(username=username) user.setPassword(newPassword) return HttpResponseRedirect("/login/") #跳转登录页面 else: forgetPasswordForm = ForgetPasswordForm() return render(request, 'forgetPasswordUI.html', locals())
def changePassword(request): if SessionManager.isAdministrator(request): return HttpResponse("管理员禁止使用修改密码功能") # 不修改 if SessionManager.isLogouted(request): return HttpResponseRedirect("/forgetpassword/") if request.method == 'POST': changePasswordForm = ChangePasswordForm(request.POST) changePasswordForm.username = SessionManager.getUsername(request) if changePasswordForm.is_valid(): oldPassword = FormsManager.getData(changePasswordForm, 'oldPassword') username = changePasswordForm.username user = UserDB.objects.get(username=username) newPassword = FormsManager.getData(changePasswordForm, 'newPassword') user.setPassword(newPassword) SessionManager.setLogout(request) return HttpResponseRedirect("/login/") #跳转登录页面 else: changePasswordForm = ChangePasswordForm() return render(request, "ChangePasswordUI.html", locals())
def register(request): if request.method == 'POST': registerForm = RegisterForm(request.POST) # 获取表单内容 if registerForm.is_valid(): # 解析表单 username = FormsManager.getData(registerForm, 'username') password = FormsManager.getData(registerForm, 'password') confirmPassword = FormsManager.getData(registerForm, 'confirmPassword') phoneNumber = FormsManager.getData(registerForm, 'phoneNumber') birthday = FormsManager.getData(registerForm, 'birthday') user = CustomerDB() # 创建空用户对象 CustomerDB.objects.create(username=username, password=password) personalInformation = PersonalInformationDB.objects.create( username=username) personalInformation.setPhoneNumber(phoneNumber) personalInformation.setBirthday(birthday) return HttpResponseRedirect("/login/") # 跳转login else: registerForm = RegisterForm() if SessionManager.isLogined(request): return HttpResponseRedirect("/") return render(request, "registerUI.html", locals()) # 正常访问,渲染模板
def logout(request): if SessionManager.isLogined(request): SessionManager.setLogout(request) return HttpResponseRedirect("/")
def cancelorder(request, number): #取消订单 username = SessionManager.getUsername(request) # 获取当前登录的用户名字 Q = BuyRecord.objects.get(username=username, number=number) #获取当前用户点击的订单对象 Q.setValid(False) #将找到的对象相应的位置为false,表明当前订单为取消状态 return render(request, 'successUI.html', locals()) # 返回修改成功信息