def dologin(request): """执行登陆""" # 验证码判断 verifycode = request.session['verifycode'] code = request.POST['code'] if verifycode != code: context = {'info': '验证码错误!'} return render(request, "myadmin/login.html", context) try: # 根据登陆账号获取用户信息 user = Model('admin') user = user.find("'" + request.POST['username'] + "'") if user is not None: import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) print(m.hexdigest()) # 校验密码是否正确 if user[0]['password'] == m.hexdigest(): # 将当前登陆成功的用户信息以adminuser这个key放入到session中 request.session['adminuser'] = user[0] return redirect(reverse('myadmin_index')) else: context = {'info': "登陆密码错误"} else: context = {'info': "此用户非后台管理账户"} except Exception as err: print(err) context = {'info': "登陆账号不存在"} return render(request, 'myadmin/login.html', context)
def pcajax_validate(request): if request.method == "POST": gt = GeetestLib(pc_geetest_id, pc_geetest_key) challenge = request.POST.get(gt.FN_CHALLENGE, '') validate = request.POST.get(gt.FN_VALIDATE, '') seccode = request.POST.get(gt.FN_SECCODE, '') status = request.session[gt.GT_STATUS_SESSION_KEY] user_id = request.POST.get('username') if status: result = gt.success_validate(challenge, validate, seccode, user_id) else: result = gt.failback_validate(challenge, validate, seccode) if result: teacher = Model('teacher') tdata = teacher.find("'" + request.POST.get('username') + "'") if tdata: import hashlib m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) if tdata[0]['password'] == m.hexdigest(): # 将当前登陆成功的用户信息以adminuser这个key放入到session中 request.session['teacher'] = tdata[0] result = {"status": "success"} # return redirect(reverse('teacher_index')) else: result = {"status": "fail"} else: result = {"status": "fail"} else: result = {"status": "fail"} return HttpResponse(json.dumps(result)) return HttpResponse("error")
def update(request, uid): """执行编辑信息""" mod = Model('admin') ob = mod.find("'" + uid + "'") import hashlib m = hashlib.md5() m.update(bytes(request.POST['old_password'], encoding='utf8')) if request.POST['password'] == request.POST['repassword'] and ob[0][ 'password'] == m.hexdigest(): mod = Model('admin') m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) kw = { 'no': uid, 'password': m.hexdigest(), } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} else: context = {"info": "修改失败"} return render(request, "myadmin/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('teaching') ob = mod.find(no=uid) teacher = Model('teacher') subject = Model('subject') list1 = teacher.find(no=uid) list2 = subject.findAll() ob[0].update({'teacher': list1[0].get('name')}) print(ob) print(list2) if ob is not None: context = {"teaching": ob, 'subject': list2} return render(request, "myadmin/teaching/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('teacher') ob = mod.find("'" + str(uid) + "'") if ob is not None: context = {"teacher": ob} return render(request, "web/teacher/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "web/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('subject') ob = mod.find(no=uid) if ob is not None: context = {"user": ob} return render(request, "myadmin/subject/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('admin') ob = mod.find(no="'" + uid + "'") print(ob) if ob is not None: context = {"user": ob} return render(request, "myadmin/vip/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def edit(request, uid): """加载编辑信息页面""" mod = Model('teacher') ob = mod.find(no=uid) mod = Model('faculty') title = mod.findAll() if ob is not None: context = {"user": ob, 'typelist': title} return render(request, "myadmin/users/edit.html", context) else: context = {"info": "没有找到要修改的信息!"} return render(request, "myadmin/info.html", context)
def teaching(request): """课程安排""" data = request.session['teacher'] uid = data.get('no') subject = Model('subject') teaching = Model('teaching') list2 = subject.findAll() list3 = teaching.find("'" + uid + "'") umod = [] for teaching in list3: dir = {} for subject in list2: if teaching.get('subject') == subject.get('no'): dir.update({ 'no': subject.get('no'), 'name': subject.get('name'), 'score': subject.get('score') }) break dir.update({'class': teaching.get('class')}) umod.append(dir) # 执行分页处理 pIndex = int(request.GET.get("p", 1)) page = Paginator(umod, 4) # 以50条每页创建分页对象 maxpages = page.num_pages # 最大页数 # 判断页数是否越界 if pIndex > maxpages: pIndex = maxpages if pIndex < 1: pIndex = 1 list2 = page.page(pIndex) # 当前页数据 # 获取页面列表信息 if maxpages < 5: plist = page.page_range # 页码数列表 else: if pIndex <= 3: plist = range(1, 6) elif pIndex >= maxpages - 3: plist = range(maxpages - 4, maxpages + 1) else: plist = range(pIndex - 2, pIndex + 3) context = { "list": list2, 'plist': plist, 'pIndex': pIndex, 'maxpages': maxpages } return render(request, "web/teacher/class.html", context)
def update(request, uid): """执行编辑信息""" mod = Model('teacher') uid = str(uid) ob = mod.find("'" + uid + "'") if request.POST['old_password'] == '': context = {"info": "请输入登录密码"} return render(request, "web/info.html", context) else: import hashlib m = hashlib.md5() m.update(bytes(request.POST['old_password'], encoding='utf8')) if ob[0]['password'] == m.hexdigest(): if request.POST['password'] != '' and request.POST[ 'password'] == request.POST['repassword']: mod = Model('teacher') m = hashlib.md5() m.update(bytes(request.POST['password'], encoding='utf8')) kw = { 'no': uid, 'password': m.hexdigest(), } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} elif request.POST['password'] == '' and request.POST['phone'] != '': kw = { 'no': uid, 'phone': request.POST['phone'], } try: if mod.update(kw) > 0: context = {"info": "修改成功!"} else: context = {"info": "修改失败"} except Exception as err: print(err) context = {"info": "修改失败"} else: context = {"info": "无修改信息"} else: context = {"info": "修改失败"} return render(request, "web/info.html", context)