예제 #1
0
파일: user.py 프로젝트: soon14/kingWeb
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())
예제 #2
0
파일: activator.py 프로젝트: soon14/kingWeb
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')