def manage_blogs_edit(blog_id): blog = Blogs.get(blog_id) if blog is None: raise HttpError.notfound() return dict(id=blog.id, name=blog.name, summary=blog.summary, content=blog.content, action=path_join(_MODULE, '/api/blogs/%s' % blog_id), redirect=path_join(_MODULE, '/manage/blogs'), user=ctx.request.user)
def manage_interceptor(next): user = ctx.request.user if user and user.admin: return next() raise HttpError.seeother(path_join(_MODULE, '/signin'))
def manage_blogs_create(): return dict(id=None, action=path_join(_MODULE, '/api/blogs'), redirect=path_join(_MODULE, '/manage/blogs'), user=ctx.request.user)
def signout(): ctx.response.delete_cookie(COOKIE_NAME) raise HttpError.seeother(path_join(_MODULE, '/'))
def manage_index(): raise HttpError.seeother(path_join(_MODULE, '/manage/comments'))
def _get_verify_list(): verify_type = ctx.request.get('verifyType', '1') verify_result = ctx.request.get('verifyResult', None) title = ctx.request.get('title', None) lists, page = _get_verify_list_by_page(verify_type, verify_result, title) param = { 'verifyType': verify_type, 'verifyResult': verify_result, 'title': title if title else '', } _format_data(lists) return dict(page=page, list=lists, param=param, user=ctx.request.user) @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'my_sampling_ip.html')) @get(path_join(_MODULE, 'myiplist')) def my_ip_list(): return _get_my_ip_sampling_list() @view(path_join(_MODULE, 'all_sampling_ip.html')) @get(path_join(_MODULE, 'alliplist')) def all_ip_list(): if ctx.request.user.crm.find('4_1_5') == -1: raise HttpError.seeother('/sampling/myiplist')
try: page_index = int(ctx.request.get('page', '1')) except ValueError: pass return page_index def _get_blogs_by_page(): total = Blogs.count_all() page = Page(total, _get_page_index()) blogs = Blogs.find_by('order by created_at desc limit ?,?', page.offset, page.limit) return blogs, page.to_dict() @interceptor(path_join(_MODULE, '/')) def user_interceptor(next): logging.info('try to bind user from session cookie...') user = None cookie = ctx.request.cookies.get(COOKIE_NAME) if cookie: logging.info('parse session cookie...') user = parse_signed_cookie(cookie) if user: logging.info('bind user <%s> to session...' % user.email) ctx.request.user = user return next() @interceptor(path_join(_MODULE, '/manage')) def manage_interceptor(next):
for x in data['copyright'].split(","): if x in copy_right.keys(): L.append(copy_right[x]) data['copyright'] = ','.join(L) if data.has_key('rightownmode') and data['rightownmode']: data['rightownmode'] = {1: u'个人作品', 2: u'合作作品'}[data['rightownmode']] if data.has_key('coper') and data['coper']: data['coper'] = json.loads(data['coper']) return data @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'list.html')) @get(path_join(_MODULE)) def home(): pn = int(ctx.request.get('pn', 1)) rn = int(ctx.request.get('rn', 10)) list_api = _API_HOST + '/copy/workchecklist?pn=%d&rn=%d&token=%s' % ( pn - 1, rn, ctx.request.cookies.get('leancloud-token')) res_data = urllib2.urlopen(list_api) res = res_data.read() res_data.close()
lists, page = _get_excellent_list_by_page(title, order) else: lists, page = _get_list_by_page(verify_type, status, has_outline, title, order) param = { 'verifyType': verify_type, 'status': status, 'hasOutline': has_outline, 'title': title if title else '', } _format_data(lists) return dict(page=page, list=lists, param=param, user=ctx.request.user) @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'ippool_list.html')) @get(path_join(_MODULE)) def ip_list(): return _get_ippool_list() @api @get(path_join(_MODULE, '/api/list')) def api_ip_list(): return _get_ippool_list()
page = Page(data['count'], pn, rn) params = { 'type': list_type, 'apiHost': _API_HOST, 'token': ctx.request.cookies.get('leancloud-token') } return dict(data=data['data'], page=page.to_dict(), param=params, user=ctx.request.user) @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) # @api @view(path_join(_MODULE, 'list.html')) @get(path_join(_MODULE, 'list')) def _list(): return _get_list('/api/tools/whiteList') # @api @view(path_join(_MODULE, 'agency_list.html')) @get(path_join(_MODULE, 'agencylist')) def _agency_list():
item.createAt, item.updateAt = time.localtime( item.createAt), time.localtime(item.updateAt) item.createAt = time.strftime('%Y-%m-%d %H:%M:%S', item.createAt) item.updateAt = time.strftime('%Y-%m-%d %H:%M:%S', item.updateAt) if hasattr(item, 'blacklistUpdateAt'): item.blacklistUpdateAt = time.localtime(item.blacklistUpdateAt) item.blacklistUpdateAt = time.strftime('%Y-%m-%d %H:%M:%S', item.blacklistUpdateAt) if hasattr(item, 'uptime'): item.uptime = time.localtime(item.uptime) item.uptime = time.strftime('%Y-%m-%d', item.uptime) @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'blacklist.html')) @get(path_join(_MODULE)) def blacklist_list(): if ctx.request.user.crm.find('4_1_8') == -1 and ctx.request.user.crm.find( '4_1_9') == -1 and ctx.request.user.crm.find('4_1_10') == -1: raise HttpError.seeother('/home') return _get_blacklist() @api
item.counts = verify_count item.days = date item.firstDay = first_days if hasattr(item, 'crm'): item['auth_name'] = get_admin_auth(*(item.crm.split(','))) if not item.ipPoolAdmin: continue item.ipPoolAdmin.createAt, item.ipPoolAdmin.updateAt = time.localtime(item.ipPoolAdmin.createAt), time.localtime(item.ipPoolAdmin.updateAt) item.ipPoolAdmin.createAt = time.strftime('%Y-%m-%d %H:%M:%S', item.ipPoolAdmin.createAt) item.ipPoolAdmin.updateAt = time.strftime('%Y-%m-%d %H:%M:%S', item.ipPoolAdmin.updateAt) @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'user_list.html')) @get(path_join(_MODULE)) def user_list(): crm = ctx.request.get('crm', None) mobile = ctx.request.get('mobile', None) users, page = _get_users_by_page(crm, mobile) return dict(page=page, list=users, user=ctx.request.user) @api @get(path_join(_MODULE, '/api/list'))
data = {} uid = uid or ctx.request.user.uid args = [uid] join = 'as a left join %s as b on a.objectId = b.objectId where b.discard = 0' % (IPPool.__table__,) where = "%s and a.adminId = ? and a.verifyResult = 0" % (join,) data['pendingCount'] = IPVerify.count_by_field(where, 'a.id', *args) where = "%s and a.adminId = ? and (a.verifyResult = 1 or a.verifyResult = 2)" % (join,) data['verifiedCount'] = IPVerify.count_by_field(where, 'a.id', *args) where = "%s and a.verifyPerson = ? and a.verifyResult = 0" % (join,) data['samplingPendingCount'] = IPSamplingVerify.count_by_field(where, 'a.id', *args) where = "%s and a.verifyPerson = ? and (a.verifyResult = 1 or a.verifyResult = 2)" % (join,) data['samplingVerifiedCount'] = IPSamplingVerify.count_by_field(where, 'a.id', *args) return data @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'home.html')) @get(path_join(_MODULE)) def home(): data = _get_verify_count() return dict(data=data, user=ctx.request.user) @api @get(path_join(_MODULE, '/api/verifycount')) def verify_count(): uid = ctx.request.get('uid', None)
} _format_data(lists) return dict(page=page, list=lists, param=param, user=ctx.request.user) def _format_data(data): for item in data: item.createAt, item.updateAt = time.localtime( item.createAt), time.localtime(item.updateAt) item.publishTime = time.localtime(item.publishTime) item.createAt = time.strftime('%Y-%m-%d %H:%M:%S', item.createAt) item.updateAt = time.strftime('%Y-%m-%d %H:%M:%S', item.updateAt) item.publishTime = time.strftime('%Y-%m-%d %H:%M:%S', item.publishTime) @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @view(path_join(_MODULE, 'verify_list.html')) @get(path_join(_MODULE)) def ip_list(): return _get_verify_list() @api @get(path_join(_MODULE, '/api/list')) def api_verify_list(): return _get_verify_list()
index = 0 admins = sorted(admins, key=lambda x: len(x['verifyList'])) for admin in admins: if index >= everyone_num: continue if ip not in admin['verifyList']: admin['verifyList'].append(ip) else: continue index += 1 return admins @interceptor(path_join(_MODULE)) def check_login_interceptor(next): return check_login(next) @interceptor(path_join(_MODULE)) def check_auth_interceptor(next): if ctx.request.user.crm.find('4_1_6') == -1 and ctx.request.user.crm.find( '4_1_7') == -1: raise HttpError.seeother('/home') return next() @view(path_join(_MODULE, 'newwriter_list.html')) @get(path_join(_MODULE))
'http://y.yunlaiwu.com/sns/luser/passlogin?username=%s&password=%s', 'development': 'http://testapi.yunlaiwu.com:8099/sns/luser/passlogin?username=%s&password=%s' }[ENV] def _login(phone, password): url = _LOGIN_URL % (phone, password) res_data = urllib2.urlopen(url) res = res_data.read() res_data.close() return json.loads(res) # 这里木有调用,允许用户在登录的情况下访问登录页面 @interceptor(path_join(_MODULE)) def user_interceptor(next): cookie = ctx.request.cookies.get(LOGIN_COOKIE_NAME) ctx.request.user = None if cookie: user = parse_signed_cookie(cookie) if user and user.id: raise HttpError.seeother('/home') return next() @view(path_join(_MODULE, 'login.html')) @get(path_join(_MODULE)) def login(): return dict()