def post(self, request): # 接收一下后台传递过来的值 check_name = request.POST.get("admin_name", None) check_password = request.POST.get("password", None) # 对数据进行验证,用户名和密码是否规范合理 check_status = Base.check_data(check_name, check_password) # 判断当前用户是否存在 info = Admins.objects.filter(admin_name=check_name).exists() if info and check_status['errors'] is None: #判断账户是否可用 status = Admins.objects.get(admin_name=check_name).is_status if status == 0: return JsonResponse({ "status": "fail", "message": "登录失败。账户不可用!", "info": "请更改密码" }) # 判断密码是否和数据库一致 pwd = Admins.objects.get(admin_name=check_name).password if pwd == check_password: ip = Base.get_ip(request) info = Admins.objects.get(admin_name=check_name) info.last_ip = ip info.save() request.session['admin_name'] = check_name # url_info = "/cms/index/" # 访问成功后跳转的路径 url_info = "/cms/" #因为检查登录状态那里已经写了跳转路径,所以此处只用写cms就可,否则会跳错 return JsonResponse({ "status": "success", "message": "登录成功,可以进入后台首页", "info": url_info }) else: return JsonResponse({ "status": "fail", "message": "登录失败。密码错误", "info": "请更改密码" }) elif info is False: return JsonResponse({ "status": "fail", "message": "当前用户不存在", "info": "请检查用户名" }) elif check_status['errors'] is not None: return JsonResponse({ "status": "fail", "message": "登录信息有误", "info": check_status['errors'] }) else: return JsonResponse({ "status": "fail", "message": "当前登录信息发生了不可知的错误,请重新输入", "info": "" })
def get(self, request): # 判断用户是否登录 status = Base.checkUserLogin(request) if status: # 获取ip和时间 ip = Base.get_ip(request) info_time = Base.getNowTime(request) # 将数据传递给前台 context = {'ip': ip, 'info_time': info_time} return render(request, 'cms/index1.html', context=context) else: return render(request, 'cms/login1.html')
def post(self, request): # 接收输入信息 check_name = request.POST.get('admin_name', None) check_pwd = request.POST.get('password', None) # 验证信息 check_status = Base.check_data(check_name, check_pwd) # 判断当前用户是存在 info = Admins.objects.filter(admin_name=check_name).exists() # 存在 if info and check_status['errors'] is None: pwd = Admins.objects.get(admin_name=check_name).password if check_password(check_pwd, pwd): # 获取信息 ip = Base.get_ip(request) info = Admins.objects.get(admin_name=check_name) info.last_ip = ip info.save() request.session['admin_name'] = check_name # request.session.set_expiry(60) request.session.set_expiry(604800) info_url = '/cms/' return JsonResponse({ 'status': 'success', 'message': '登录成功,可以进入首页', 'info': info_url }) else: return JsonResponse({ 'status': 'fail', 'message': '登录失败,密码错误', 'info': "请重新输入密码" }) elif info == False: return JsonResponse({ 'status': 'fail', 'message': '当前用户不存在', 'info': '请检查用户名' }) elif check_status['errors'] is not None: return JsonResponse({ 'status': 'fail', 'message': '登录信息错误', 'info': check_status['errors'] }) else: return JsonResponse({ 'status': 'fail', 'message': '出现未知错误,请重新输入', 'info': '' })
def get(self, request): # 判断是或否登录 status = Base.checkUserLogin(request) # 已经登录的情况 if status: ad_name = request.session.get('admin_name') ad_user = Admins.objects.get(admin_name=ad_name) # 获取时间和ip ip = Base.get_ip(request) NowTime = Base.getNowTime(request) # 从传递信息给前台 context = {"ip": ip, "info_time": NowTime, 'ad_user': ad_user} return render(request, 'cms/index.html', context=context) else: return render(request, 'cms/login.html')
def post(self, request): article_avatar = request.FILES.get('avatar') content = request.POST.get('content') title = request.POST.get('title') sourceTitle = request.POST.get('sourceTitle') sourceUrl = request.POST.get('sourceUrl') tag = request.POST.get('tags') school = request.POST.get('school', None) if school == '': school = None if title == '': return JsonResponse({ 'status': 'fail', 'message': '请输入文章标题', 'tagid': 'title' }) Posts.objects.create(post_title=title, post_image=article_avatar, source=sourceTitle, source_link=sourceUrl, post_content=content, edit_time=Base.getNowTime(request), school_id=school, tags_id=tag) return JsonResponse({ 'status': 'success', 'message': '添加成功', 'info': '', })
def post(self, request): post_id = request.POST.get('post_id') title = request.POST.get('title') content = request.POST.get('content') sourceTitle = request.POST.get('sourceTitle') sourceUrl = request.POST.get('sourceUrl') keyWord = request.POST.get('keyWord') cate = request.POST.get('cate') count = request.POST.get('reader') if title == '': return JsonResponse({ 'status': 'fail', 'message': '请输入文章标题', 'tagid': 'title' }) else: info = ServerPosts.objects.get(id=post_id) info.post_title = title info.post_content = content info.source = sourceTitle info.source_link = sourceUrl info.keywords = keyWord info.cateid_id = cate info.edit_time = Base.getNowTime(request) info.views = count info.save() return JsonResponse({ 'status': 'success', 'message': '修改成功', 'info': '' })
def get(self, request): # 判断用户是否登录: login_status = Base.checkUserLogin(request) if login_status: return redirect('/cms/index/') else: return render(request, 'cms/login.html')
def get(self, request): # 检查登录状态 login_status = Base.checkUserLogin(request) if login_status: return render(request, 'cms/index1.html') else: return render(request, 'cms/login1.html')
def post(self, request): # 接收前台数据 check_name = request.POST.get('admin_name') check_pwd = request.POST.get('pwd') # 对数据进行校验 check_status = Base.check_data(check_name, check_pwd) # 判断用户名是否注册 info = Admin.objects.filter(admin_name=check_name).exists() if info and check_status['errors'] is None: if Admin.objects.get(admin_name=check_name).password == check_pwd: ip = Base.get_ip(request) info = Admin.objects.get(admin_name=check_name) info.last_ip = ip info.last_time = Base.getNowTime(request) info.save() request.session['admin_name'] = check_name # print('/cms/index/?id=' + str(info.id)) return JsonResponse({ 'status': 'success', 'message': '登录成功,可以跳转后台页面', 'info': '/cms/index/?id=' + str(info.id), }) else: return JsonResponse({ 'status': 'fail', 'message': '密码错误', 'info': '' }) elif not info: return JsonResponse({ 'status': 'fail', 'message': '用户名不存在', 'info': '' }) elif check_status['errors']: return JsonResponse({ 'status': 'fail', 'message': check_status['errors'], 'info': '' }) else: return JsonResponse({ 'status': 'fail', 'message': '存在不可预知的错误', 'info': '' })
def post(self, request): manager_name = request.POST.get('manager_name') password = request.POST.get('password') manager = Admin.objects.filter(admin_name=manager_name).exists() if manager: return JsonResponse({ 'sutatus': 'fail', 'message': '用户名已存在', 'info': manager_name }) Admin.objects.create(admin_name=manager_name, password=password, is_status=1, reg_ip=Base.get_ip(request), reg_time=Base.getNowTime(request)) return JsonResponse({ 'status': 'success', 'message': '添加成功', 'info': manager_name, })
def post(self, request): nickname = request.POST.get('nickname', None) info = Users.objects.filter(nickname=nickname).exists() if info: return JsonResponse({ "status": "fail", "message": "当前用户已存在", "tagid": 'nickname' }) # 增加数据 Users.objects.create(nickname=nickname, password=make_password( request.POST.get('password', None)), email=request.POST.get('email', None), reg_ip=Base.get_ip(request), reg_time=Base.getNowTime(request)) return JsonResponse({ "status": "success", "message": "创建成功", "info": '' })
def post(self, request): admin_name = request.POST.get('admin_name', None) password = request.POST.get('password', None) #判断管理员是否存在 info = Admins.objects.filter(admin_name=admin_name).exists() if info: #如果为true,控制台返回值 return JsonResponse({ 'status': 'fail', 'message': '当前用户已存在', 'tagid': 'admin_name' }) #如果不存在就增加管理员数据 Admins.objects.create(admin_name=admin_name, password=password, req_ip=Base.get_ip(request), req_time=Base.getNowTime(request)) return JsonResponse({ 'status': 'success', 'message': '创建成功', 'info': '' })
def post(self, request): admin_name = request.POST.get('admin_name', None) info = Admins.objects.filter(admin_name=admin_name).exists() if info: return JsonResponse({ 'status': 'fail', 'message': '当前用户已存在', 'tagid': 'nickname', }) # 增加数据 else: Admins.objects.create(admin_name=admin_name, password=make_password( request.POST.get("password", None)), reg_time=Base.getNowTime(request), reg_ip=Base.get_ip(request)) return JsonResponse({ 'status': 'success', 'message': '添加成功', 'info': '' })
def post(self, request): nickname = request.POST.get('nickname', None) #判断用户是否存在 info = Users.objects.filter(nickname=nickname).exists() if info: #如果为true,控制台返回值 return JsonResponse({ 'status': 'fail', 'message': '当前用户已存在', 'tagid': 'nickname' }) #如果不存在就增加用户数据 Users.objects.create( nickname=nickname, password=make_password(request.POST.get('password', None)), #密码加密处理 email=request.POST.get('email', None), reg_ip=Base.get_ip(request), reg_time=Base.getNowTime(request)) return JsonResponse({ 'status': 'success', 'message': '创建成功', 'info': '' })
def get(self, request): # 判断用户是否登录 admin_id = request.GET.get('id') status_login = Base.checkUserLogin(request) if status_login and admin_id: # # 获取ip和时间 # ip = Base.get_ip(request) # info_time = Base.getNowTime(request) # 根据IP获取用户 admin = Admin.objects.get(pk=admin_id) # 将数据传递前台 context = {'admin': admin} return render(request, 'cms/index.html', locals()) else: request.session.flush() return redirect('/cms/login/')
def post(self, request): post_id = request.POST.get('post_id') article_avatar = request.FILES.get('avatar') print(article_avatar) content = request.POST.get('content') title = request.POST.get('title') sourceTitle = request.POST.get('sourceTitle') sourceUrl = request.POST.get('sourceUrl') count = request.POST.get('count') tag = request.POST.get('tags') school = request.POST.get('school', None) if article_avatar != None: pos = Posts.objects.get(id=post_id) pos.post_image = article_avatar pos.save() if school == '': school = None if title == '': return JsonResponse({ 'status': 'fail', 'message': '请输入文章标题', 'tagid': 'title' }) Posts.objects.filter(id=post_id).update( post_title=title, source=sourceTitle, source_link=sourceUrl, post_content=content, edit_time=Base.getNowTime(request), views=count, school_id=school, tags_id=tag) return JsonResponse({ 'status': 'success', 'message': '修改成功', 'info': '', })
def post(self, request): # 获取手机号 phone = request.POST.get('phone', '') print('手机号 %s' % phone) image_code, verify_code = '', '' # 获取图片验证码 captchaStr = request.POST.get('image_code', '') captchaHashkey = request.POST.get('hashkey', '') # print(captchaHashkey) if captchaStr and captchaHashkey: try: # 获取根据hashkey获取数据库中的response值 get_captcha = CaptchaStore.objects.get(hashkey=captchaHashkey) # 如果验证码匹配 if get_captcha.response == captchaStr.lower(): image_code = True else: image_code = False return JsonResponse({ 'status': 'fail', 'msg': '验证码错误', 'tagname': '.image_code_error' }) except: image_code = False return JsonResponse({ 'status': 'fail', 'msg': '未知错误', 'tagname': '.image_code_error' }) # 获取手机验证码 phoneCode = request.POST.get('phoneCode', '') # print('手机验证码:%s' %phoneCode) if phoneCode: try: verify = VerifyCode.objects.order_by('-id').get(mobile=phone) if phoneCode == verify.code: verify_code = True else: # verify_code = False verify_code = True # return JsonResponse({ # 'status': 'fail', # 'msg': '手机验证码错误', # 'tagname': '.phone_code_error' # }) except: # verify_code = False verify_code = True # 检查是否存在手机号 try: is_user = Users.objects.get(phone=phone) except: Users.objects.create(nickname=str(phone), phone=phone, reg_time=Base.getNowTime(request), reg_ip=Base.get_ip(request), is_status=1) # print('check_mobile') # 验证图片验证码和短信验证码是否正确 if image_code == True and verify_code == True: request.session['user_phone'] = phone request.session.set_expiry(600) # 设置最后登录时间和最后登录ip user = Users.objects.get(phone=phone) user.last_time = Base.getNowTime(request) user.last_ip = Base.get_ip(request) user.save() # a = request.session.get('user_phone',None) # print('session信息 %s' %a) return JsonResponse({'status': 'success', 'msg': '成功'}) else: return JsonResponse({ 'status': 'fail', 'msg': '信息输入有误', 'tagname': '.image_code_error' })