def post_login(request, kwargs): assert isinstance(request, HttpRequest) result = ResultModel() username = request.POST.get('UserName') pwd = request.POST.get('Password') if request.method == 'GET': result.msg = 'Method not allowed' return JsonResponse(result.tojson()) user = auth.authenticate(username=username, password=pwd) if user is not None: userprofile = SysUserProfile.objects.get(user=user) if userprofile.status == UserStatus.active.value: auth.login(request, user) result.data = user.username result.flag = True result.msg = '登陆成功' else: result.data = user.username result.msg = '登陆失败:用户状态为' + UserStatus(userprofile.status).name else: result.msg = '登陆失败' ip = WebHelper.get_client_ip(request) agent = WebHelper.get_client_agent(request) SysLoginlog.objects.create(clientip=ip, clientinfo=agent, username=username, description=result.msg) return JsonResponse(result.tojson())
def post_edit(request,kwargs): assert isinstance(request, HttpRequest) result = ResultModel() id = request.POST.get('id','') obj = SysModule.objects.get(id=id) modelform = SysModuleForm(WebHelper.get_post_dic(request.POST),instance=obj).save() result.msg = '操作成功' result.flag = True return JsonResponse(result.tojson())
def process(request, **kwargs): '''接收所有匹配url的请求,根据请求url中的参数,通过反射动态指定view中的方法''' app = kwargs.get('app', None) controller = kwargs.get('controller', None) action = kwargs.get('action', None) ip = WebHelper.get_client_ip(request) agent = WebHelper.get_client_agent(request) user = request.user url = request.get_full_path() #POST请求就不写入日志了 if request.method != 'POST': SysOperationLog.objects.create(clientip=ip,clientinfo = agent,username=user.username,operationdescription='访问',\ operationurl = url) SysHelper.userid = str(user.id) try: viewObj = __import__("kingWeb.apps.%s.views" % (app, ), fromlist=(controller, )) ctrlObj = getattr(viewObj, controller) actionObj = getattr(ctrlObj, action) #执行view.py中的函数,并获取其返回值 result = actionObj(request, kwargs) return result except (ImportError, AttributeError) as e: LogHelper.error(str(e)) if request.method == 'POST': result = ResultModel() result.flag = False result.msg = '操作失败:' + str(e) return JsonResponse(result.tojson()) else: return redirect('/adm/home/error') except Exception as e: LogHelper.error(str(e)) if request.method == 'POST': result = ResultModel() result.flag = False result.msg = '操作失败:' + str(e) return JsonResponse(result.tojson()) else: return redirect('/adm/home/error')
def post_edit(request, kwargs): assert isinstance(request, HttpRequest) result = ResultModel() id = request.POST.get('id', '') parentid = request.POST.get('parentid', '') obj = SysMenu.objects.get(id=id) postdic = WebHelper.get_post_dic(request.POST) if not parentid: postdic['parentid'] = '0' type = get_menu_type(parentid) #根据父菜单设置此子菜单的类型 postdic['type'] = type modelform = SysMenuForm(postdic, instance=obj).save() result.msg = '操作成功' result.flag = True return JsonResponse(result.tojson())