def column_info(json_data=None, muilt=False): if json_data is None: json_data = {} from conn import MongoHelp if muilt: return MongoHelp('Column').find(json_data) else: return MongoHelp('Column').find_one(json_data)
def __set_classid(self, class_id): self.req_permisssion = class_id self.__class_id = class_id self.__class_info = MongoHelp('Column').find_one({'class_id': class_id}) if self.__class_info['type'] not in MongoHelp('Setting').find_one( {'set_type': 'content'})['content_default'].keys(): raise Exception('Content set Error: %s' % self.__class_info['type']) self.__content_default = MongoHelp('Setting').find_one( {'set_type': 'content'})['content_default'][self.__class_info['type']]['data']
def __init__(self, user_info=None): ClassTool.__init__(self) self.__conn = MongoHelp('Permission') self.__conn_user = MongoHelp('User') self.__conn_settings = MongoHelp('Setting') self.__permission_model = self.__conn_settings.find_one( {"set_type": "permission_model"}) from user import User if isinstance(user_info, User): self.user = user_info self.__allow_list = self.__allow()
def __init__(self, user_info=None): ClassTool.__init__(self) self.__conn = MongoHelp('Push') from user import User if isinstance(user_info, User): self.user = user_info self._push = jpush.JPush(app_key, master_secret).create_push()
def __init__(self, user_info=None): ClassTool.__init__(self) if isinstance(user_info, User): self.user = user_info self.__conn = MongoHelp('User') self.__conn_setting = MongoHelp('Setting').find_one( {'set_type': 'system'}) self.__salt = self.__conn_setting['user_salt'] self.__raw_data = MongoHelp('Setting').find_one( {'set_type': 'raw_data'}) self.__permission = self.__raw_data['permission'] self.__group_range = MongoHelp('Permission').find_one( {'group_name': self.user.group})['control'] else: # raise Exception('Plz input User case') pass
def info_update(self, info): if not self.is_login: return { 'success': False, '_id': '', 'apikey': '', 'error': 'Login Failed' } user_data = self.user_data user_id = user_data['_id'] user_default = MongoHelp('Setting').find_one({'set_type': 'raw_data' })['user_default'] for n in info.keys(): if n not in ['username', 'password'] and n in user_default.keys(): if n != 'permission': if isinstance(info[n], str): user_data[n] = info[n] elif isinstance(info[n], dict): for m in info[n].keys(): user_data[n][m] = info[n][m] for i in ['_id', 'username', 'password']: del user_data[i] is_update = self.__conn_user.fix_one({'_id': user_id}, user_data) if is_update: return {'success': True, '_id': user_id, 'apikey': '', 'error': ''} else: return { 'success': False, '_id': user_id, 'apikey': '', 'error': 'Update Failed' }
def __init__(self, **kwargs): for i in ['ident', 'pwd', 'apikey', 'visitor']: if i in kwargs: break else: raise Exception('Login Fail') self.__conn_user = MongoHelp('User') self.__conn_setting = MongoHelp('Setting').find_one( {'set_type': 'system'}) self.user_data, self.is_login, self.group, self.permission = None, False, None, None if kwargs.get('visitor', False): self.__visitor_login() elif kwargs.get('apikey', False): self.__apikey_login(kwargs['apikey']) else: self.__user_login((kwargs['ident'], kwargs['pwd'])) pass
def modify(self, ident, info): if not info or not isinstance(info, dict): raise Exception('Update what? need dict data') if not self.__group_range: raise Exception('Need update_user Permission') if ident.isdigit() and len(ident) == 11: key = 'phone' else: key = 'username' user_data = self.__conn.find_one({key: ident}) if not user_data: return self._sys_msg(False, 'ident error, check out!', {'_id': ''}) user_id = user_data['_id'] user_default = self.__raw_data['user_default'] for n in info.keys(): if n not in ['username', 'password'] and n in user_default.keys(): if n == 'permission': if info[n].get('group') not in self.__group_range: return self._sys_msg(False, 'Permission Limit', {'_id': ''}) else: if 'group' in info[n].keys(): user_data[n]['group'] = info[n]['group'] if 'tag' in info[n].keys(): system_mod = MongoHelp('Setting').find_one( {'set_type': 'system'})['all_fuc'].keys() for m in info[n].keys(): if m in system_mod: if m in user_data[n]['tag'].keys(): user_data[n]['tag'][m].extend( info[n][m]) else: user_data[n]['tag'][m] = info[n][m] else: if isinstance(info[n], str): user_data[n] = info[n] elif isinstance(info[n], dict): for m in info[n].keys(): user_data[n][m] = info[n][m] for i in ['_id', 'username', 'password']: del user_data[i] is_update = self.__conn.fix_one({'_id': user_id}, user_data) return self._sys_msg(is_update, 'Update Failed', {'_id': is_update})
def reset_pwd(is_request=True, **kwargs): db_conn = MongoHelp('User') if is_request: if 'username' not in kwargs.keys(): raise Exception('Need username to request reset password!') try: import random reset_code = '%06d' % random.randint(0, 999999) db_conn.fix_one({'username': kwargs['username']}, {'reset_code': reset_code}) return { 'success': True, 'reset_code': reset_code, 'error': '', 'fuc_name': 'UserMod#reset_pwd' } except Exception, e: return { 'success': False, 'reset_code': '', 'error': 'reset_pwd: %s' % e, 'fuc_name': 'UserMod#reset_pwd' }
def __init__(self): self.conn = MongoHelp('Images')
# coding=utf-8 from conn import MongoHelp __author__ = 'dolacmeo' __doc__ = '模块装饰器' setting_conn = MongoHelp('Setting') is_super_disable = setting_conn.find_one({'set_type': 'system'})['super_user']['disable'] func_registered = setting_conn.find_one({'set_type': 'system'})['all_fuc'].keys() def ModVerify(func): """ 验证用户权限,处理数据结果,注册功能模块 :param func: """ content_less_permission = ['UserMod', 'PermissionMod'] def wrapper(*args, **kwargs): if len(args) == 0: raise Exception('Used within class.func') user_model = args[0].user class_name = args[0].__class__.__name__ fuc_name = args[0].__class__.__name__ + '#' + func.__name__ print '%s:' % fuc_name if not user_model.is_login: raise Exception('Need User login first') if (fuc_name in user_model.permission.keys()) \ or (user_model.group == 'super' and not is_super_disable):
def __allow(self): if self.user.group == 'super': return MongoHelp('Setting').find_one({'set_type': 'system'})['all_fuc'].keys() return self.user.user_data['permission']['tag'].keys()
def __init__(self, user_info=None): ClassTool.__init__(self) self.__conn = MongoHelp('Comment') from user import User if isinstance(user_info, User): self.user = user_info
def Setting_setup(self): from conn import MongoHelp return MongoHelp('Setting')
def setting_info(set_type): from conn import MongoHelp return MongoHelp('Setting').find_one({'set_type': set_type})
'fuc_name': 'UserMod#reset_pwd' } except Exception, e: return { 'success': False, 'reset_code': '', 'error': 'reset_pwd: %s' % e, 'fuc_name': 'UserMod#reset_pwd' } else: for n in ['username', 'code', 'newpwd']: if n not in kwargs.keys(): raise Exception('Need %s to reset password!' % n) user_data = db_conn.find_one({'username': kwargs['username']}) if kwargs['code'] == user_data.get('reset_code'): salt = MongoHelp('Setting').find_one({'set_type': 'system'})['user_salt'] user_data['password'] = hashlib.md5(salt + kwargs['newpwd'] + salt).hexdigest() user_id = user_data['_id'] for i in ['_id', 'reset_code']: del user_data[i] print user_data is_reset = db_conn.fix_one({'_id': user_id}, user_data) if is_reset: db_conn.fix_one({'_id': user_id}, {'reset_code': 1}, '$unset') return { 'success': True, '_id': user_id, 'error': '', 'fuc_name': 'UserMod#reset_pwd'