def jscode(self): ct = request.headers.get('Content-Type', '') form = request.json if 'json' in ct else request.form code = form.get('code') if code: url = self.get_jscode_url(code) res = requests.get(url).json() if 'openid' in res: return self.success(res) current_app.logger.error('jscode: ' + json.dumps(res)) return json_error(msg='获取session_key失败') elif current_user.is_authenticated(): um.funcs.on_wechat_login('mini', '') try: if Item.bool('allow_invite', False, name='允许渠道'): um.funcs.on_wechat_login('mini', '') current_user.wechat_user.update_info( form.get('userInfo'), action='mini') current_user.wechat_user.save() current_user.wechat_user.sync(current_user) current_user.save() except: current_app.logger.error(traceback.format_exc()) return json_success(data=um.funcs.userinfo(current_user)) return json_error(key='LOGIN_REQIURED')
def trace_log(): user = None if current_user.is_authenticated(): user = current_user.id if current_app.config.get('FAST_MODE') is True: return json_success() TraceLog( user=user, key=request.form.get('key', ''), tid=request.form.get('tid', ''), label=request.form.get('label', ''), value=request.form.get('value', ''), ).save() return json_success()
def trace(): key = request.form.get('key') tid = request.form.get('tid') user = current_user.id if current_user.is_authenticated() else None label = request.form.get('label') value = request.form.get('value', json.dumps(request.form)) if key and value: TraceLog(key=key, tid=tid, user=user, label=label, value=value).save() return json_success()
def handled(self): id = request.form.get('id') if id.split('_')[0] == 'true': complaints = self.model.objects(user=id.split('_')[1], active=False).first() if complaints and complaints.user.complaint: complaints.active = True complaints.save() return json_error(msg='该用户之前已被封') if complaints and not complaints.user.complaint: complaints.user.complaint = True complaints.active = True complaints.result = '%s\n%s' % (dict( result='complaint success', num='%d' % len(complaints.result.split('\n')) if complaints.result else '1'), complaints.result if complaints.result else '') complaints.save() complaints.user.save() return json_success(msg='封号成功', id='#%s' % id.split('_')[1]) if id.split('_')[0] == 'false': complaints = self.model.objects(user=id.split('_')[1], active=True).first() if complaints and not complaints.user.complaint: complaints.active = False complaints.save() return json_error(msg='该用户未被封') if complaints and complaints.user.complaint: complaints.user.complaint = False complaints.active = False complaints.result = '%s\n%s' % (dict( result='complaint release', num='%d' % len(complaints.result.split('\n')) if complaints.result else '1'), complaints.result if complaints.result else '') complaints.save() complaints.user.save() return json_success(msg='解封成功', id='#%s' % id.split('_')[1]) return ''
def save_menu(self): menus = request.form.get('menus') Item.set_data('admin_menus', menus, name='管理菜单') filename = current_app.get_data_path('admin.menus.json') with open(filename, 'w+') as fd: fd.write(menus) for admin in current_app.extensions.get('admin', []): admin._refresh() return json_success(msg='保存成功')
def complaint_refer(): types = request.form.get('type', '') content = request.form.get('content', '') complaints = Complaint( user=current_user.id, content=content, type=types, active=True, ) complaints.create() complaints.save() return json_success(msg='success', num=complaints.id)
def saveresult(self): _id = request.form.get('id', None) model = self.model.objects(id=_id).first() if not model: json_error(msg='无该记录') result = request.form.get('result') remark = request.form.get('remark') model.result = result model.remark = remark model.save() return json_success(msg='保存成功')
def success(self, access): user = um.funcs.get_wechat_user(access, 'mini') try: if not user: userinfo = dict( openid=access['openid'], unionid=access.get('unionid', ''), session_key=access.get('session_key'), ) user = um.funcs.create_wechat_user(userinfo, 'mini') else: user.modify( unionid=access.get('unionid', ''), session_key=access.get('session_key'), modified=datetime.now(), ) um.funcs.wechat_login(user) if user.user: real_user = um.models.User.objects(id=user.user).first() if not real_user: user.user = 0 user.save() else: user = real_user login_user(user, remember=True) if current_user.is_authenticated() and current_user.is_user(): um.models.UserLog.login(user.id, 'web', 'mini') user.login() except: current_app.logger.error(traceback.format_exc()) if request.args.get('access') == 'true': return json_success(data=um.funcs.userinfo(user), access=access) return json_success(data=um.funcs.userinfo(user))
def share_log(): media = request.form.get('media') title = request.form.get('title') desc = request.form.get('desc') image = request.form.get('image') link = request.form.get('link') status = request.form.get('status') user = current_user.id if current_user.is_authenticated() else None if media and status: log = ShareLog(user=user, media=media, title=title, desc=desc, image=image, link=link, status=status) log.save() return json_success()
def dropdown(self): id = request.args.get('id', 0, unicode) val = request.args.get('key', '') name = request.args.get('name', '', unicode) value = request.args.get('value', '', unicode) model = self.model if not val: val = 'false' if value == 'false' or value == 'False' or value is False else 'true' if type(val) == int: val = int(val) obj = model.objects(id=id).first() if obj: self.on_field_change(obj, name, val) obj.save() return json_success() return json_error(msg='该记录不存在')
def save_menu(self): menus = request.form.get('menus') Item.set_data('admin_menus', menus, name='管理菜单') for admin in current_app.extensions.get('admin', []): admin._refresh() return json_success(msg='保存成功')