예제 #1
0
    def get(self):
        ps = self.get_page_config('后台')
        token = self.get_args(['token'], '')
        ps['token'] = token['token']
        user = self.current_user
        if None == user:
            ''' 判断用户是否存在,如果不存在,判断token重新登录 '''
            if '' == ps['token']:
                params = {
                    'backUrl': config.urls['adminBackUrl'],
                    'appCode': ps['appCode']
                }
                url = self.format_url(config.urls['loginUrl'], params)
                self.redirect(url)
                return
            else:
                user = soc_right_proxy.get_login_user(token=ps['token'])
                if user == '' or type(user) != dict or user.get('email',
                                                                '') == '':
                    '''  无法获取用户信息,重新登录 '''
                    self.redirect(config.urls['loginUrl'])
                    return
                else:
                    rights = user.get('rights', [])

                uuid = str_helper.get_uuid()
                redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
                ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut'])
                self.set_cookie(name=config.SOCPMConfig['adminCookieName'],
                                value=uuid,
                                expires=ex)
        ps['user'] = user

        self.render('admin/main.html', **ps)
예제 #2
0
 def get(self):
     ps = self.get_page_config('后台')
     token = self.get_args(['token'], '')
     ps['token'] = token['token']
     user = self.current_user        
     if None == user:
         ''' 判断用户是否存在,如果不存在,判断token重新登录 '''
         if '' == ps['token']:
             params = {'backUrl':config.urls['adminBackUrl'], 'appCode': ps['appCode']}
             url = self.format_url(config.urls['loginUrl'] , params)
             self.redirect(url)
             return
         else:
             user = soc_right_proxy.get_login_user(token = ps['token'])
             if None == user or type(user) != dict or user.get('email','') == '':
                 '''  无法获取用户信息,重新登录 '''
                 self.redirect(config.urls['loginUrl'])
                 return
             else:
                 rights = user.get('rights', [])
                 
                 #for right in rights:
                 #    right['']
             uuid = str_helper.get_uuid()
             redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
             ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut'])
             self.set_cookie(name = config.SOCRightConfig['adminCookieName'], value=uuid, expires=ex)
     ps['user'] = user
     
     self.render('admin/main.html', **ps)
예제 #3
0
def get_goto_user_url( userID, appCode, ip, backUrl = ''):
    '''   
        保存为这样的格式:
        {"id": 1, "tel": "123", "email": "*****@*****.**", "name": "\u4f59\u6d77", "rights": 
            [{"id":12, "path":"xx.aa", "realName":"abc","right":1, "customRight": [1,2,3]}, {"id":13, "path":"xx.aa.bb","right":1, "customRight": []}]}

{"code":0,"msg":"OK","data":{"tel": "123", "name": "yuhai", "rights": [{"path": "SOCRight.Login", "right": 15, "id": 18, "customRight": []}, 
{"path": "SOCRight.AppManager", "right": 15, "id": 9, "customRight": []}, {"path": "SOCRight.FuncManager", "right": 15, "id": 10, "customRight": [1, 2]},
{"path": "SOCRight.UserManager", "right": 15, "id": 11, "customRight": []}, {"path": "SOCRight.UserManager.UserBindRoleManager", "right": 15, "id": 14, "customRight": []},
{"path": "SOCRight.UserGroupManager", "right": 15, "id": 12, "customRight": []}, 
{"path": "SOCRight.UserGroupManager.UserGroupBindRoleManager", "right": 15, "id": 15, "customRight": []}, 
{"path": "SOCRight.UserGroupManager.UserGroupBindUserManager", "right": 15, "id": 16, "customRight": []}, {"path": "SOCRight.RoleManager", "right": 15, "id": 13, "customRight": []}, 
{"path": "SOCRight.RoleManager.RoleBindRightManager", "right": 15, "id": 17, "customRight": []}], "mobile": "123", "id": 1, "email": "*****@*****.**", "realName": "\u4f59\u6d77"}}
    '''
    u = query_one(userID)
    if None == u:
        return None
    user = {}
    user['id'] = u['id']
    user['realName'] = u['realName']
    user['email'] = u['email']
    user['mobile'] = u['mobile']
    user['tel'] = u['tel']
    user['name'] = u['name']

    funcs = query_user_app_right(userID = userID, appCode = appCode)
    rights = []
    rightType = False
    if None != funcs and len(funcs) > 0:
        for func in funcs:
            right = {}
            right['id'] = func['id']
            right['path'] = func['path']
            right['right'] = func.get('right', 0)
            if right['right'] > 0 and not rightType:
                rightType = True
            cr = []
            if func['customJson'] != None:
                for j in func['customJson']:
                    if j['right']:
                        cr.append(j['k'])
            right['customRight'] = cr
            rights.append(right)
    
    user['rights'] = rights    
    uuid = str_helper.get_uuid()            
    redis_cache.setObj(uuid, user, config.cache['userRightTimeOut'])
    params = {'token':uuid}
    if backUrl != '':
        gotoUrl = str_helper.format_url(url = backUrl, params = params)
    else:
        app = application_logic.query_one(code = appCode)
        gotoUrl = str_helper.format_url(url = app['url'], params = params)
    update_goto_app(name = user['name'], appCode = appCode, ip = ip)
    return gotoUrl
예제 #4
0
def reset_password( name):
    passWord = str_helper.get_uuid()
    isdelete = state.Boole['false']
    pw = _format_user_password_md5(passWord)        
    yz = (pw, name, isdelete)

    result = mysql.insert_or_update_or_delete(_update_password_sql, yz)
    
    if 0 == result:
        return passWord
    return None
예제 #5
0
    def post(self):
        ps = self.get_page_config('登录')

        host = self.request.host
        if host not in ps['serviceSiteDomain']:
            self.redirect(ps['siteDomain'] + 'Admin')

        ps = self.get_args(
            ls=['backUrl', 'appCode', 'userName', 'passWord'], default='', map=ps)
        if ps['userName'] == '' or ps['passWord'] == '':
            self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100001')
            return
        user = user_logic.login(ps['userName'], ps['passWord'])
        if None == user:
            self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100002')
            return

        uuid = str_helper.get_uuid()
        redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
        ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut'])
        self.clear_all_cookies()
        self.set_cookie(name=config.SOCRightConfig[
                        'rightCookieName'], value=uuid, expires=ex)

        '''  记录日志 '''
        ac = ps['appCode']
        if None == ac or '' == ac:
            ac = 'SOCRight'
        oper_log_logic.add(operID=user['id'], operUserName=user['name'], operRealName=user[
                                                   'realName'], appCode=ac, funcPath='', action='userLogin', targetType=0, targetID='', targetName='', startStatus='', endStatus='', operIp=self.get_user_ip())


        if None != user['loginCount'] and 0 >= user['loginCount'] and 'passwordedit' not in self.request.path.lower():
            params = {'msg': '100003'}
            url = self.format_url(config.SOCRightConfig[
                                  'serviceSiteDomain'] + 'PassWordEdit', params)
            self.redirect(url)
            return

        if ps['appCode'] != '':
            if None == user['loginCount'] or 0 == user['loginCount']:
                self.redirect(ps['serviceSiteDomain'] + 'PassWordEdit?msg=100003&appCode=' +
                              str_helper.url_escape(ps['appCode']) + '&backUrl=' + 
                              str_helper.url_escape(ps['backUrl']))            

            backUrl = user_logic.get_goto_user_url(
                userID=user['id'], appCode=ps['appCode'], ip=self.get_user_ip(), backUrl=ps['backUrl'])

            self.redirect(backUrl)
        else:
            self.redirect(ps['serviceSiteDomain'] + 'AppList')
예제 #6
0
 def get_user_info_by_token(self , token):
     user = soc_right_proxy.get_login_user(token = token)
     if None == user or type(user) != dict or user.get('email','') == '':
         '''  无法获取用户信息,重新登录 '''
         self.redirect(config.urls['loginUrl'])
         return
     else:
         rights = user.get('rights', [])
     user['loginToken'] = token
     uuid = str_helper.get_uuid()
     redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
     ex = datetime.now() + timedelta(seconds=config.cache['userTimeOut'])
     self.set_cookie(name = config.SOCRightConfig['adminCookieName'], value=uuid, expires=ex)
     return user
예제 #7
0
 def get_user_info_by_token(self, token):
     user = soc_right_proxy.get_login_user(token=token)
     if None == user or type(user) != dict or user.get('email', '') == '':
         '''  无法获取用户信息,重新登录 '''
         self.redirect(config.urls['loginUrl'])
         return
     else:
         rights = user.get('rights', [])
     user['loginToken'] = token
     uuid = str_helper.get_uuid()
     redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
     ex = datetime.now() + timedelta(seconds=config.cache['userTimeOut'])
     self.set_cookie(name=config.SOCRightConfig['adminCookieName'],
                     value=uuid,
                     expires=ex)
     return user
예제 #8
0
 def post(self):
     ps = self.get_page_config('登录')
     ps['appcode'] = self.get_arg('appcode', ps['appcode'])
     username = self.get_arg('username', '')
     password = self.get_arg('password', '')        
     if username == '' or password == '':
         self.redirect("/Login?msg=100001")
         return
     user = user_logic.login(username, password, ps['appcode'])
     if None == user:
         self.redirect("/Login?msg=100002")
         return
     uuid = str_helper.get_uuid()
     redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
     self.set_cookie(name = config.SOCRightConfig['cookiename'], value=uuid, expires=config.cache['userTimeOut'])
     self.render("login.html", **ps)
예제 #9
0
 def post(self):
     ps = self.get_page_config('登录')
     ps['appcode'] = self.get_arg('appcode', ps['appcode'])
     username = self.get_arg('username', '')
     password = self.get_arg('password', '')        
     if username == '' or password == '':
         self.redirect("/Login?msg=100001")
         return
     user = user_logic.UserLogic.instance().login(username, password, ps['appcode'])
     if None == user:
         self.redirect("/Login?msg=100002")
         return
     uuid = str_helper.get_uuid()
     redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
     self.set_cookie(name = config.SOCRightConfig['cookiename'], value=uuid, expires=config.cache['userTimeOut'])
     self.render("login.html", **ps)
예제 #10
0
 def post(self):
     ps = self.get_page_config("登录")
     ps["appcode"] = self.get_arg("appcode", ps["appcode"])
     username = self.get_arg("username", "")
     password = self.get_arg("password", "")
     if username == "" or password == "":
         self.redirect("/Login?msg=100001")
         return
     user = user_logic.UserLogic.instance().login(username, password, ps["appcode"])
     if None == user:
         self.redirect("/Login?msg=100002")
         return
     uuid = str_helper.get_uuid()
     print uuid
     user = json_encode(user)
     redis_cache.set(uuid, user, config.cache["userTimeOut"])
     self.set_cookie(name=config.SOCPMConfig["cookiename"], value=uuid, expires=config.cache["userTimeOut"])
     self.render("login.html", **ps)
예제 #11
0
    def get(self):

        type = self.check_oper_right_custom_right(self._rightKey, self._exportUserKey)
        if type == False:
            self.redirect(config.SOCRightConfig['siteDomain']+'Admin/NotRight')
            return

        import sys
        reload(sys)                        
        sys.setdefaultencoding('utf-8')    
        ps = self.get_page_config(title = '导出用户Excel')
        user = self.get_args(['id', 'realName', 'name', 'tel', 'mobile', 'email', 'createTimeBegin', 'createTimeEnd', 'lastUpdateTimeBegin', 'lastUpdateTimeEnd'], '')
        user['status'] = int(self.get_arg('status', '0'))
        user['departmentID'] = int(self.get_arg('departmentID', '0'))
        ps['deps'] = department_logic.query_all_by_active()
        ps['page'] = int(self.get_arg('page', '1'))
        ps['userStatus'] = state.UserStatus
        ps['pagedata'] = user_logic.query_page(id = user['id'],
                    name = user['name'], realName = user['realName'], departmentID = user['departmentID'],
                     tel = user['tel'], mobile = user['mobile'], email = user['email'], 
                     status = user['status'], createTimeBegin = user['createTimeBegin'], createTimeEnd = user['createTimeEnd'], lastUpdateTimeBegin = user['lastUpdateTimeBegin'], lastUpdateTimeEnd = user['lastUpdateTimeEnd'], page = ps['page'], size = 9999)

        users = ps['pagedata']['data']

        #生成excel文件
        info = u'''<table><tr><td>用户ID</td><td>用户名</td><td>姓名</td><td>部门</td><td>状态</td>
                    <td>最后登录时间</td><td>创建人</td><td>创建时间</td><td>最后更新人</td><td>最后更新时间</td></tr>'''

        for user in users:
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
                    <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (str(user['id']), user['name'], user['realName'], 
                        user['departmentName'], user['statusname'], user['lastLoginTime'], user['creater'], str(user['createTime'])[0:-3], 
                        user['lastUpdater'], str(user['lastUpdateTime'])[0:-3] )
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig['exportUserPath'] + str_helper.get_now_datestr() +'_'+ str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName
        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close( )    
        self.redirect(config.SOCRightConfig['siteDomain']+fileName)
예제 #12
0
    def get(self):

        type = self.check_oper_right_custom_right(self._rightKey, self._exportUserKey)
        if type == False:
            self.redirect(config.SOCRightConfig['siteDomain']+'Admin/NotRight')
            return

        import sys
        reload(sys)                        
        sys.setdefaultencoding('utf-8')    
        ps = self.get_page_config(title = '导出用户Excel')
        user = self.get_args(['id', 'realName', 'name', 'tel', 'mobile', 'email', 'createTimeBegin', 'createTimeEnd', 'lastUpdateTimeBegin', 'lastUpdateTimeEnd'], '')
        user['status'] = int(self.get_arg('status', '0'))
        user['departmentID'] = int(self.get_arg('departmentID', '0'))
        ps['deps'] = department_logic.query_all_by_active()
        ps['page'] = int(self.get_arg('page', '1'))
        ps['userStatus'] = state.UserStatus
        ps['pagedata'] = user_logic.query_page(id = user['id'],
                    name = user['name'], realName = user['realName'], departmentID = user['departmentID'],
                     tel = user['tel'], mobile = user['mobile'], email = user['email'], 
                     status = user['status'], createTimeBegin = user['createTimeBegin'], createTimeEnd = user['createTimeEnd'], lastUpdateTimeBegin = user['lastUpdateTimeBegin'], lastUpdateTimeEnd = user['lastUpdateTimeEnd'], page = ps['page'], size = 999999)

        users = ps['pagedata']['data']

        userGroups = usergroup_logic.query_user_user_group(id = user['id'],
                    name = user['name'], realName = user['realName'], departmentID = user['departmentID'],
                     tel = user['tel'], mobile = user['mobile'], email = user['email'], 
                     status = user['status'], createTimeBegin = user['createTimeBegin'], createTimeEnd = user['createTimeEnd'], lastUpdateTimeBegin = user['lastUpdateTimeBegin'], lastUpdateTimeEnd = user['lastUpdateTimeEnd'])

        userGroupRoles = role_logic.query_user_user_group_role(id = user['id'],
                    name = user['name'], realName = user['realName'], departmentID = user['departmentID'],
                     tel = user['tel'], mobile = user['mobile'], email = user['email'], 
                     status = user['status'], createTimeBegin = user['createTimeBegin'], createTimeEnd = user['createTimeEnd'], lastUpdateTimeBegin = user['lastUpdateTimeBegin'], lastUpdateTimeEnd = user['lastUpdateTimeEnd'])

        userRoles =  role_logic.query_user_role(id = user['id'],
                    name = user['name'], realName = user['realName'], departmentID = user['departmentID'],
                     tel = user['tel'], mobile = user['mobile'], email = user['email'], 
                     status = user['status'], createTimeBegin = user['createTimeBegin'], createTimeEnd = user['createTimeEnd'], lastUpdateTimeBegin = user['lastUpdateTimeBegin'], lastUpdateTimeEnd = user['lastUpdateTimeEnd'])

        userGroupMap = {}
        rolesMap = {}

        for user in users:
            uid = str(user['id'])
            ug = []
            ugids = []
            #检索用户的所属用户组
            for userGroup in userGroups:
                if uid == str(userGroup['userID']):
                    ug.append(userGroup['userGroupName'])
                    ugids.append(str(userGroup['userGroupID']))
            userGroupMap[str(uid)] = ','.join(ug)

            ur = []
            for userRole in userRoles:
                if uid == str(userRole['userID']):
                    ur.append(userRole['roleName'])

            for ugid in ugids:
                for userGroupRole in userGroupRoles:
                    if ugid == str(userGroupRole['userGroupID']):
                        if userGroupRole['roleName'] not in ur:
                            ur.append(userGroupRole['roleName'])
            rolesMap[uid] = ','.join(ur)

        #生成excel文件
        info = u'''<table><tr><td>用户ID</td><td>用户名</td><td>姓名</td><td>部门</td><td>状态</td><td>锁定时间</td>
                    <td>最后登录时间</td><td>创建人</td><td>创建时间</td><td>最后更新人</td><td>最后更新时间</td><td>绑定用户组</td><td>绑定角色</td></tr>'''

        for user in users:
            uid = str(user['id'])
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
                    <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (str(user['id']), user['name'], user['realName'], 
                        user['departmentName'], user['statusname'], str(user['lockTime'])[0:-3], user['lastLoginTime'], user['creater'], str(user['createTime'])[0:-3], 
                        user['lastUpdater'], str(user['lastUpdateTime'])[0:-3], userGroupMap.get(uid,''), rolesMap.get(uid,''))
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig['exportUserPath'] + str_helper.get_now_datestr() +'_'+ str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName
        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close( )    
        self.redirect(config.SOCRightConfig['siteDomain']+fileName)
예제 #13
0
    def get(self):

        type = self.check_oper_right_custom_right(self._rightKey,
                                                  self._exportUserKey)
        if type == False:
            self.redirect(config.SOCRightConfig['siteDomain'] +
                          'Admin/NotRight')
            return

        import sys
        reload(sys)
        sys.setdefaultencoding('utf-8')
        ps = self.get_page_config(title='导出用户Excel')
        user = self.get_args([
            'id', 'realName', 'name', 'tel', 'mobile', 'email',
            'createTimeBegin', 'createTimeEnd', 'lastUpdateTimeBegin',
            'lastUpdateTimeEnd'
        ], '')
        user['status'] = int(self.get_arg('status', '0'))
        user['departmentID'] = int(self.get_arg('departmentID', '0'))
        ps['deps'] = department_logic.query_all_by_active()
        ps['page'] = int(self.get_arg('page', '1'))
        ps['userStatus'] = state.UserStatus
        ps['pagedata'] = user_logic.query_page(
            id=user['id'],
            name=user['name'],
            realName=user['realName'],
            departmentID=user['departmentID'],
            tel=user['tel'],
            mobile=user['mobile'],
            email=user['email'],
            status=user['status'],
            createTimeBegin=user['createTimeBegin'],
            createTimeEnd=user['createTimeEnd'],
            lastUpdateTimeBegin=user['lastUpdateTimeBegin'],
            lastUpdateTimeEnd=user['lastUpdateTimeEnd'],
            page=ps['page'],
            size=999999)

        users = ps['pagedata']['data']

        userGroups = usergroup_logic.query_user_user_group(
            id=user['id'],
            name=user['name'],
            realName=user['realName'],
            departmentID=user['departmentID'],
            tel=user['tel'],
            mobile=user['mobile'],
            email=user['email'],
            status=user['status'],
            createTimeBegin=user['createTimeBegin'],
            createTimeEnd=user['createTimeEnd'],
            lastUpdateTimeBegin=user['lastUpdateTimeBegin'],
            lastUpdateTimeEnd=user['lastUpdateTimeEnd'])

        userGroupRoles = role_logic.query_user_user_group_role(
            id=user['id'],
            name=user['name'],
            realName=user['realName'],
            departmentID=user['departmentID'],
            tel=user['tel'],
            mobile=user['mobile'],
            email=user['email'],
            status=user['status'],
            createTimeBegin=user['createTimeBegin'],
            createTimeEnd=user['createTimeEnd'],
            lastUpdateTimeBegin=user['lastUpdateTimeBegin'],
            lastUpdateTimeEnd=user['lastUpdateTimeEnd'])

        userRoles = role_logic.query_user_role(
            id=user['id'],
            name=user['name'],
            realName=user['realName'],
            departmentID=user['departmentID'],
            tel=user['tel'],
            mobile=user['mobile'],
            email=user['email'],
            status=user['status'],
            createTimeBegin=user['createTimeBegin'],
            createTimeEnd=user['createTimeEnd'],
            lastUpdateTimeBegin=user['lastUpdateTimeBegin'],
            lastUpdateTimeEnd=user['lastUpdateTimeEnd'])

        userGroupMap = {}
        rolesMap = {}

        for user in users:
            uid = str(user['id'])
            ug = []
            ugids = []
            #检索用户的所属用户组
            for userGroup in userGroups:
                if uid == str(userGroup['userID']):
                    ug.append(userGroup['userGroupName'])
                    ugids.append(str(userGroup['userGroupID']))
            userGroupMap[str(uid)] = ','.join(ug)

            ur = []
            for userRole in userRoles:
                if uid == str(userRole['userID']):
                    ur.append(userRole['roleName'])

            for ugid in ugids:
                for userGroupRole in userGroupRoles:
                    if ugid == str(userGroupRole['userGroupID']):
                        if userGroupRole['roleName'] not in ur:
                            ur.append(userGroupRole['roleName'])
            rolesMap[uid] = ','.join(ur)

        #生成excel文件
        info = u'''<table><tr><td>用户ID</td><td>用户名</td><td>姓名</td><td>部门</td><td>状态</td><td>锁定时间</td>
                    <td>最后登录时间</td><td>创建人</td><td>创建时间</td><td>最后更新人</td><td>最后更新时间</td><td>绑定用户组</td><td>绑定角色</td></tr>'''

        for user in users:
            uid = str(user['id'])
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
                    <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (
                str(user['id']), user['name'], user['realName'],
                user['departmentName'], user['statusname'],
                str(user['lockTime'])[0:-3], user['lastLoginTime'],
                user['creater'], str(user['createTime'])[0:-3],
                user['lastUpdater'], str(user['lastUpdateTime'])[0:-3],
                userGroupMap.get(uid, ''), rolesMap.get(uid, ''))
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig[
            'exportUserPath'] + str_helper.get_now_datestr(
            ) + '_' + str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName
        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close()
        self.redirect(config.SOCRightConfig['siteDomain'] + fileName)
예제 #14
0
    def get(self):
        # type = self.check_oper_right_custom_right(self._rightKey, self._exportUserKey)
        # if type == False:
        #     self.redirect(config.SOCRightConfig['siteDomain']+'Admin/NotRight')
        #     return

        import sys
        reload(sys)                        
        sys.setdefaultencoding('utf-8')    
        ps = self.get_page_config(title = '导出角色用户列表Excel')

        role = {}
        role['id'] = int(self.get_arg('id', '0'))
        role = role_logic.query_one(id = role['id'])
        ps['userName'] = self.get_arg('userName', '')        
        ps['page'] = int(self.get_arg('page', '1'))
        ps['pagedata'] = user_logic.query_page_by_roleid(roleID = role['id'], userName = ps['userName'], page = 1, size = 99999)

        users = ps['pagedata']['data']

        #生成excel文件
        info = u'''<table><tr><td>用户ID</td><td>用户名</td><td>姓名</td><td>部门名称</td><td>角色ID</td><td>角色名</td></tr>'''

        for user in users:
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (str(user['id']), user['name'], user['realName'], 
                        user['departmentName'], role['id'], role['name'] )
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig['exportUserPath'] + str_helper.get_now_datestr() +'_'+ str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName
        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close( )    
        self.redirect(config.SOCRightConfig['siteDomain']+fileName)
예제 #15
0
    def get(self):
        type = self.check_oper_right_custom_right(self._rightKey, self._exportUserKey)
        if type == False:
            self.redirect(config.SOCRightConfig['siteDomain']+'Admin/NotRight')
            return

        import sys
        reload(sys)                        
        sys.setdefaultencoding('utf-8')   
        ps = self.get_page_config(title = '导出操作日志列表')

        operLog = self.get_args(['operUserName', 'action', 'beginTime', 'endTime'], '')
        operLog['operID'] = int(self.get_arg('operID', '0'))
        ps['page'] = int(self.get_arg('page', '1'))
        ps['pagedata'] = oper_log_logic.query_page(operID = operLog['operID'], operUserName = operLog['operUserName'], appCode = '', funcPath = '', action = operLog['action'], operIp = '', beginTime = operLog['beginTime'], endTime = operLog['endTime'], page = ps['page'], size = 99999)
        
        #生成excel文件
        logs = ps['pagedata']['data']
        info = u'''<table><tr><td>id</td><td>操作用户ID</td><td>操作用户名</td><td>操作用户姓名</td><td>操作IP</td>
                    <td>操作时间</td><td>应用编号</td><td>操作类型</td><td>操作目标类型</td><td>操作目标ID</td>
                    <td>操作目标名称</td></tr>'''

        for log in logs:
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>
                    <td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (str(log['id']), log['operID'], log['operUserName'], 
                        log['operRealName'], log['operIp'], str(log['operTime'])[0:-3], log['appCode'], log['actionname'], str(log['targetType']), 
                        log['targetID'], log['targetName'] )
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig['exportOperLogPath'] + str_helper.get_now_datestr() +'_'+ str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName

        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close( )    
        self.redirect(config.SOCRightConfig['siteDomain']+fileName)
예제 #16
0
    def get(self):
        # type = self.check_oper_right_custom_right(self._rightKey, self._exportUserKey)
        # if type == False:
        #     self.redirect(config.SOCRightConfig['siteDomain']+'Admin/NotRight')
        #     return

        import sys
        reload(sys)                        
        sys.setdefaultencoding('utf-8')    
        ps = self.get_page_config(title = '导出角色用户列表Excel')

        role = {}
        role['id'] = int(self.get_arg('id', '0'))
        role = role_logic.query_one(id = role['id'])
        ps['userName'] = self.get_arg('userName', '')        
        ps['page'] = int(self.get_arg('page', '1'))
        ps['pagedata'] = user_logic.query_page_by_roleid(roleID = role['id'], userName = ps['userName'], page = 1, size = 99999)

        users = ps['pagedata']['data']

        #生成excel文件
        info = u'''<table><tr><td>用户ID</td><td>用户名</td><td>姓名</td><td>部门名称</td><td>角色ID</td><td>角色名</td></tr>'''

        for user in users:
            u = u'''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>''' % (str(user['id']), user['name'], user['realName'], 
                        user['departmentName'], role['id'], role['name'] )
            info = info + u
        info = info + u'</table>'
        fileName = config.SOCRightConfig['exportUserPath'] + str_helper.get_now_datestr() +'_'+ str_helper.get_uuid() + '.xls'

        path = config.SOCRightConfig['realPath'] + fileName
        file_object = open(path, 'w')
        file_object.write(info)
        file_object.close( )    
        self.redirect(config.SOCRightConfig['siteDomain']+fileName)
예제 #17
0
    def post(self):
        ps = self.get_page_config('登录')

        host = self.request.host
        if host not in ps['serviceSiteDomain']:
            self.redirect(ps['siteDomain'] + 'Admin')

        ps = self.get_args(ls=['backUrl', 'appCode', 'userName', 'passWord'],
                           default='',
                           map=ps)
        if ps['userName'] == '' or ps['passWord'] == '':
            self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100001')
            return
        user = user_logic.login(ps['userName'], ps['passWord'])
        if None == user:
            self.redirect(ps['serviceSiteDomain'] + 'Login?msg=100002')
            return

        uuid = str_helper.get_uuid()
        redis_cache.setObj(uuid, user, config.cache['userTimeOut'])
        ex = ps['now'] + timedelta(seconds=config.cache['userTimeOut'])
        self.clear_all_cookies()
        self.set_cookie(name=config.SOCRightConfig['rightCookieName'],
                        value=uuid,
                        expires=ex)
        '''  记录日志 '''
        ac = ps['appCode']
        if None == ac or '' == ac:
            ac = 'SOCRight'
        oper_log_logic.add(operID=user['id'],
                           operUserName=user['name'],
                           operRealName=user['realName'],
                           appCode=ac,
                           funcPath='',
                           action='userLogin',
                           targetType=0,
                           targetID='',
                           targetName='',
                           startStatus='',
                           endStatus='',
                           operIp=self.get_user_ip())

        if None != user['loginCount'] and 0 >= user[
                'loginCount'] and 'passwordedit' not in self.request.path.lower(
                ):
            params = {'msg': '100003'}
            url = self.format_url(
                config.SOCRightConfig['serviceSiteDomain'] + 'PassWordEdit',
                params)
            self.redirect(url)
            return

        if ps['appCode'] != '':
            if None == user['loginCount'] or 0 == user['loginCount']:
                self.redirect(ps['serviceSiteDomain'] +
                              'PassWordEdit?msg=100003&appCode=' +
                              str_helper.url_escape(ps['appCode']) +
                              '&backUrl=' +
                              str_helper.url_escape(ps['backUrl']))

            backUrl = user_logic.get_goto_user_url(userID=user['id'],
                                                   appCode=ps['appCode'],
                                                   ip=self.get_user_ip(),
                                                   backUrl=ps['backUrl'])

            self.redirect(backUrl)
        else:
            self.redirect(ps['serviceSiteDomain'] + 'AppList')