def get(self): user_id = self.current_user['user_id'] share_id = self.get_argument("delete", None) s = self.get_argument("s", None) if admin.is_admin(user_id): if share_id and not s: admin.delete_share(share_id) if share_id and s and admin.is_superadmin(user_id): admin.delete_share_by_s(share_id) if s: shares = Share.find({'status': {'$ne': 1}}) self.render('admin/super_share.html', shares=shares) else: shares = Share.find() self.render('admin/share.html', shares=shares) else: self.render('admin/join_admin.html')
def get(self): user_id = self.current_user['user_id'] delete_share_id = self.get_argument("delete", None) status = self.get_argument("status", 0) status = int(status) s = self.get_argument("s", None) # super if admin.is_admin(user_id): if delete_share_id and not s: admin.delete_share(delete_share_id) if delete_share_id and s and admin.is_superadmin(user_id): admin.delete_share_by_s(delete_share_id) # shares = Share.find({'status': {'$ne': 1}}).sort('_id', -1) if status == 100: status = {'$gt': 3} shares = Share.find({'status': status}).sort('_id', -1) if s: self.render('admin/super_share.html', shares=shares) else: self.render('admin/share.html', shares=shares) else: self.render('admin/join_admin.html')
def get(self): user = User.by_sid(self.current_user['user_id']) # 删除敏感信息 auser = dict(user) auser.pop('_id') auser.pop('user_pass') # 获取头像 if user.user_email.endswith('@wechat'): user['gravatar'] = get_avatar_by_wechat(user._id) else: auser['gravatar'] = get_avatar(user.user_email, 100) # auser['user_tags'] = [] auser['user_tags_info'] = [] for tag in auser['user_tags']: info = {} info['name'] = tag if tag in d_tag_desc: info['desc'] = d_tag_desc[tag] else: info['desc'] = '...' if tag in d_tag_lang: eng = d_tag_lang[tag] # info['img'] = 'https://anwensf.com/static/info/_{}.jpg'.format(eng.lower()) info['img'] = 'https://anwen.cc/static/info/_{}_100.jpg'.format(eng.lower()) else: # https://search.creativecommons.org/photos/27c13378-faf4-4d9e-ad0d-0b9459403aeb # https://live.staticflickr.com/7291/11240475435_ce223d84e2_b.jpg # the img is in public domain info['img'] = 'https://anwen.cc/static/info/public_domain_100.jpg' auser['user_tags_info'].append(info) # 添加管理员信息 auser['is_admin'] = admin.is_admin(auser['id']) if auser['id'] in wx_admin_ids: auser['is_admin'] = True # 输出 self.res = auser return self.write_json()
def get(self): user_id = self.current_user['user_id'] if admin.is_admin(user_id): self.render('admin/admin.html') else: self.render('admin/join_admin.html')
def get(self): wx_code = self.get_argument("code", '') appname = self.get_argument("appname", '') if not wx_code or not appname: return self.write_error(401) wx_api = 'https://api.weixin.qq.com/sns/jscode2session' params = {} params['appid'] = appinfo[appname]['WX_APPID'] params['secret'] = appinfo[appname]['WX_SECRET'] params['js_code'] = wx_code params['grant_type'] = 'authorization_code' r = requests.get(wx_api, params=params, timeout=5) r = r.json() session_key = r.get('session_key') openid = r.get('openid') if not session_key or not openid: print(r) # return self.write_json() return self.write_error(402) # 复用email password doc = User.by_email(openid + '@wechat') if doc: doc.update( { 'user_pass': session_key, } ) doc.save() user_info = { 'user_id': doc.id, 'user_email': doc.user_email, 'user_name': doc.user_name, 'user_domain': doc.user_domain, } token = self.create_signed_value( 'user', tornado.escape.json_encode(user_info)) self.res['token'] = token.decode('u8') self.res['is_admin'] = admin.is_admin(doc['id']) if doc['id'] in wx_admin_ids: self.res['is_admin'] = True return self.write_json() else: # res['id'] = User.find().count() + 1 res = {} res['user_email'] = openid + '@wechat' res['user_pass'] = session_key res['user_name'] = 'null' user = User.new(res) user_info = { 'user_id': user.id, 'user_email': user.user_email, 'user_name': user.user_name, 'user_domain': user.user_domain, } token = self.create_signed_value( 'user', tornado.escape.json_encode(user_info)) self.res['token'] = token.decode('u8') return self.write_json()
def post(self): user = User.by_sid(self.current_user['user_id']) # Do not save user info if not necessary # 小程序的用户信息: # avatarUrl String 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640 * 640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。 # city nickName # 没有用到的暂时没有保存: # gender String 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知 # province String 用户所在省份 # country String 用户所在国家 # language String 用户的语言,简体中文为zh_CN # iv # signature # encryptedData # isignaturev # 获取待更新字段 tags = self.get_argument('tags', None) remove_tag = self.get_argument('remove_tag', None) name = self.get_argument('name', None) if not name: name = self.get_argument('nickName', None) avatar_url = self.get_argument('avatarUrl', None) city = self.get_argument('city', None) say = self.get_argument('say', None) # 更新信息 if avatar_url: try: r = requests.get(avatar_url) if r.status_code == 200: avatar_dir = 'static/avatar' size = 'raw' avatar_path = '%s/%s_%s.jpg' % (avatar_dir, user.id, size) with open(avatar_path, 'wb') as f: for chunk in r.iter_content(): f.write(chunk) print('saved avatar') except Exception as e: print('Error:', e) if city: user['user_city'] = city if name: user['user_name'] = name if say: user['user_say'] = say raw_rags = user['user_tags'] if tags: new_tags = tags.strip().split(',') for t in new_tags: if t not in raw_rags: raw_rags.append(t) if remove_tag: if remove_tag in raw_rags: raw_rags.remove(remove_tag) user['user_tags'] = raw_rags user.save() is_admin = admin.is_admin(user['id']) # user['is_admin'] = # user.pop('_id') # 只输出指定信息 auser = {} auser['user_tags'] = user['user_tags'] auser['is_admin'] = is_admin if user['id'] in wx_admin_ids: auser['is_admin'] = True self.res = auser return self.write_json()