Exemplo n.º 1
0
 def EmptyCurrent(response, request):
     try:
         if ParameterService.GetServiceConfig(
                 CommonUtils.Current(response, request),
                 'LoginProvider') == 'Cookie':
             response.delete_cookie(
                 ParameterService.GetServiceConfig(
                     CommonUtils.Current(response, request),
                     'LoginProvider'))
         else:
             request.session.clear()
     except Exception as e:
         print(e)
Exemplo n.º 2
0
def UpdateUserConfig(request):

    if request.POST['themeJson']:

        response = HttpResponse()
        vUser = CommonUtils.Current(response, request)

        jobj = json.loads(request.POST['themeJson'])
        pageSize = str(jobj['gridRows'])
        themeName = str(jobj['theme']['name'])
        navType = str(jobj['navType'])
        returnValue = 0

        if pageSize:
            returnValue = returnValue + ParameterService.SetParameter(
                vUser, "User", vUser.Id, "WebPageSize", pageSize)
        if themeName:
            returnValue = returnValue + ParameterService.SetParameter(
                vUser, "User", vUser.Id, "WebTheme", themeName)
            response.set_signed_cookie(
                'theme',
                themeName,
                max_age=int(
                    ParameterService.GetServiceConfig(
                        CommonUtils.Current(response, request),
                        'CookieMaxAge')),
                salt=ParameterService.GetServiceConfig(
                    CommonUtils.Current(response, request), 'LoginUserKey'))
        if navType:
            returnValue = returnValue + ParameterService.SetParameter(
                vUser, "User", vUser.Id, "NavType", navType)
            response.set_signed_cookie(
                'UIStyle',
                navType,
                max_age=int(
                    ParameterService.GetServiceConfig(
                        CommonUtils.Current(response, request),
                        'CookieMaxAge')),
                salt=ParameterService.GetServiceConfig(
                    CommonUtils.Current(response, request), 'LoginUserKey'))
        if returnValue > 0:
            response.content = '1'
        else:
            response.content = '保存失败!'
        return response
    else:
        response = HttpResponse()
        response.content = "无保存数据!"
        return response
Exemplo n.º 3
0
 def wrapped_function(*args, **kwargs):
     if ParameterService.GetServiceConfig(None,
                                          'LoginProvider') == 'Cookie':
         try:
             user = args[0].get_signed_cookie(
                 ParameterService.GetServiceConfig(
                     None, 'LoginProvider'),
                 salt=ParameterService.GetServiceConfig(
                     None, 'LoginUserKey'))
             if user:
                 user = SecretHelper.AESDecrypt(user)
                 try:
                     user = json.loads(user,
                                       object_hook=UserInfo.json_2_obj)
                     if PublicController.IsAuthorized(
                             HttpResponse(), args[0], code):
                         return func(*args, **kwargs)
                     else:
                         return HttpResponseRedirect('/Admin/Index/')
                 except:
                     return HttpResponseRedirect('/Admin/Index/')
             else:
                 return HttpResponseRedirect('/Admin/Index/')
         except Exception as e:
             print(e)
             return HttpResponseRedirect('/Admin/Index/')
     else:
         try:
             user = args[0].session.get(
                 ParameterService.GetServiceConfig(
                     None, 'LoginProvider'))
             if user:
                 user = SecretHelper.AESDecrypt(user)
                 try:
                     user = json.loads(user,
                                       object_hook=UserInfo.json_2_obj)
                     if PublicController.IsAuthorized(
                             HttpResponse(), args[0], code):
                         return func(*args, **kwargs)
                     else:
                         return HttpResponseRedirect('/Admin/Index/')
                 except:
                     return HttpResponseRedirect('/Admin/Index/')
             else:
                 return HttpResponseRedirect('/Admin/Index/')
         except Exception as e:
             print(e)
             return HttpResponseRedirect('/Admin/Index/')
Exemplo n.º 4
0
    def __call__(self, *args, **kw):

        if ParameterService.GetServiceConfig(None,
                                             'LoginProvider') == 'Cookie':
            try:
                user = args[0].get_signed_cookie(
                    ParameterService.GetServiceConfig(None, 'LoginProvider'),
                    salt=ParameterService.GetServiceConfig(
                        None, 'LoginUserKey'))
                if user:
                    user = SecretHelper.AESDecrypt(user)

                    try:
                        user = json.loads(user,
                                          object_hook=UserInfo.json_2_obj)
                    except:
                        return HttpResponseRedirect('/Admin/Index/')
                    return self.f(*args, **kw)
                else:
                    return HttpResponseRedirect('/Admin/Index/')
            except Exception as e:
                print(e)
                return HttpResponseRedirect('/Admin/Index/')
        else:
            try:
                user = args[0].session.get(
                    ParameterService.GetServiceConfig(None, 'LoginProvider'))
                if user:
                    user = SecretHelper.AESDecrypt(user)
                    try:
                        user = json.loads(user,
                                          object_hook=UserInfo.json_2_obj)
                    except:
                        return HttpResponseRedirect('/Admin/Index/')
                    return self.f(*args, **kw)
                else:
                    return HttpResponseRedirect('/Admin/Index/')
            except Exception as e:
                print(e)
                #TODO:这个地方只是暂时用来记录异常信息的代码,应当将不同模块不同方法的异常记录写到各自的代码中,后期此代码要删除
                e_out = Ciexception()
                e_out.id = uuid.uuid4()
                e_out.createon = datetime.datetime.now()
                e_out.message = e
                ExceptionService.Add(None, e_out)

                return HttpResponseRedirect('/Admin/Index/')
Exemplo n.º 5
0
def GetDefaultConfig(request):
    response = HttpResponse()
    vUser = CommonUtils.Current(response, request)
    curTheme = ParameterService.GetParameter(vUser, "User", vUser.Id,
                                             "WebTheme")
    curPageSize = ParameterService.GetParameter(vUser, "User", vUser.Id,
                                                "WebPageSize")
    curNavType = ParameterService.GetParameter(vUser, "User", vUser.Id,
                                               "NavType")

    if curTheme:
        if ParameterService.GetServiceConfig(
                CommonUtils.Current(response, request),
                'LoginProvider') == 'Cookie':
            response.set_signed_cookie(
                'theme',
                curTheme,
                max_age=int(
                    ParameterService.GetServiceConfig(
                        CommonUtils.Current(response, request),
                        'CookieMaxAge')),
                salt=ParameterService.GetServiceConfig(
                    CommonUtils.Current(response, request), 'LoginUserKey'))

    outJson = "{"
    if curTheme:
        outJson = outJson + "\"theme\":{\"title\":\"默认皮肤\",\"name\":\"" + curTheme + "\",\"selected\":true}"
    else:
        outJson = outJson + "\"theme\":{\"title\":\"默认皮肤\",\"name\":\"default\",\"selected\":true}"

    if curPageSize:
        outJson = outJson + ",\"gridRows\":" + curPageSize
    else:
        outJson = outJson + ",\"gridRows\":20"

    if curNavType:
        outJson = outJson + ",\"navType\":\"" + curNavType + "\"}"
    else:
        outJson = outJson + ",\"navType\":\"AccordionTree\"}"

    response.content = outJson
    return response
Exemplo n.º 6
0
    def Theme(response, request):
        tmpTheme = "default"
        vUser = CommonUtils.Current(response, request)
        if vUser:
            tmpTheme = ParameterService.GetParameter(
                CommonUtils.Current(response, request), 'User', vUser.Id,
                'WebTheme')
        if not tmpTheme:
            tmpTheme = 'default'

        request.session['theme'] = tmpTheme
        response.set_signed_cookie(
            'theme',
            tmpTheme,
            max_age=int(
                ParameterService.GetServiceConfig(
                    CommonUtils.Current(response, request), 'CookieMaxAge')),
            salt=ParameterService.GetServiceConfig(
                CommonUtils.Current(response, request), 'LoginUserKey'))
        return tmpTheme
Exemplo n.º 7
0
    def UIStyle(userInfo, response, request):
        tmpUIStyle = "AccordionTree"
        vUser = CommonUtils.Current(response, request)
        if userInfo:
            try:
                tmpUIStyle = ParameterService.GetParameter(
                    CommonUtils.Current(response, request), 'User',
                    userInfo.Id, 'NavType')
            except:
                tmpUIStyle = 'AccordionTree'
        else:
            tmpUIStyle = 'AccordionTree'

        request.session['UIStyle'] = tmpUIStyle
        response.set_signed_cookie(
            'UIStyle',
            tmpUIStyle,
            max_age=int(
                ParameterService.GetServiceConfig(
                    CommonUtils.Current(response, request), 'CookieMaxAge')),
            salt=ParameterService.GetServiceConfig(
                CommonUtils.Current(response, request), 'LoginUserKey'))
        return tmpUIStyle
Exemplo n.º 8
0
 def Current(response, request):
     if ParameterService.GetServiceConfig(None,
                                          'LoginProvider') == 'Cookie':
         try:
             user = request.get_signed_cookie(
                 ParameterService.GetServiceConfig(None, 'LoginProvider'),
                 salt=ParameterService.GetServiceConfig(
                     None, 'LoginUserKey'))
             #user =  pickle.loads(user)
             user = SecretHelper.AESDecrypt(user)
             user = json.loads(user, object_hook=UserInfo.json_2_obj)
             return user
         except Exception as e:
             return None
     else:
         try:
             user = request.session.get(
                 ParameterService.GetServiceConfig(None, 'LoginProvider'))
             user = SecretHelper.AESDecrypt(user)
             user = json.loads(user, object_hook=UserInfo.json_2_obj)
             return user
         except Exception as e:
             print(e)
             return None
Exemplo n.º 9
0
 def AddCurrent(user, response, request):
     """
     写入登录信息
     Args:
         user (UserInfo): user
     Returns:
     """
     try:
         if ParameterService.GetServiceConfig(
                 CommonUtils.Current(response, request),
                 'LoginProvider') == 'Cookie':
             #user = pickle.dumps(user)
             user = json.dumps(user, default=UserInfo.obj_2_json)
             #response.set_signed_cookie(ParameterService.GetServiceConfig('LoginProvider'), str(user), max_age=int(ParameterService.GetServiceConfig('CookieMaxAge')), salt=ParameterService.GetServiceConfig('LoginUserKey'))
             user = SecretHelper.AESEncrypt(user)
             user = str(user, encoding="utf8")
             response.set_signed_cookie(
                 ParameterService.GetServiceConfig(
                     CommonUtils.Current(response, request),
                     'LoginProvider'),
                 user,
                 max_age=int(
                     ParameterService.GetServiceConfig(
                         CommonUtils.Current(response, request),
                         'CookieMaxAge')),
                 salt=ParameterService.GetServiceConfig(
                     CommonUtils.Current(response, request),
                     'LoginUserKey'))
         else:
             #user = pickle.dumps(user)
             user = json.dumps(user, default=UserInfo.obj_2_json)
             user = SecretHelper.AESEncrypt(user)
             user = str(user, encoding="utf8")
             request.session[ParameterService.GetServiceConfig(
                 CommonUtils.Current(response, request),
                 'LoginProvider')] = user
             request.session.set_expiry(
                 int(
                     ParameterService.GetServiceConfig(
                         CommonUtils.Current(response, request),
                         'CookieMaxAge')))
     except Exception as e:
         print(e)