def insert_data(self, post_data): title = post_data["title"][0] uu = self.get_by_wiki(title) if uu is None: pass else: return False if post_data["src_type"][0] == "1": cnt_html = tools.rst2html(post_data["cnt_md"][0]) else: cnt_html = tools.markdown2html(post_data["cnt_md"][0]) entry = CabWiki.create( title=post_data["title"][0], date=datetime.datetime.now(), cnt_html=cnt_html, uid=tools.get_uu8d(), time_create=tools.timestamp(), user_name=post_data["user_name"], cnt_md=tornado.escape.xhtml_escape(post_data["cnt_md"][0]), time_update=tools.timestamp(), view_count=1, src_type=post_data["src_type"][0], ) return entry.uid
def insert_data(self, post_data): title = post_data['title'][0] uu = self.get_by_wiki(title) if uu is None: pass else: return (False) if post_data['src_type'][0] == '1': cnt_html = tools.rst2html(post_data['cnt_md'][0]) else: cnt_html = tools.markdown2html(post_data['cnt_md'][0]) entry = CabWiki.create(title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, uid=tools.get_uu8d(), time_create=tools.timestamp(), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape( post_data['cnt_md'][0]), time_update=tools.timestamp(), view_count=1, src_type=post_data['src_type'][0]) return (entry.uid)
def add_or_update(self, post_data): entry = TabLayout.create( uid=tools.get_uu8d(), title='', app=post_data['map'][0], user=post_data['user'], json=post_data['geojson'][0] if 'geojson' in post_data else '', lon=float(post_data['lon'][0]), lat=float(post_data['lat'][0]), zoom=int(post_data['zoom'][0]), marker=int(post_data['marker'][0]) if 'marker' in post_data else 0, time_create=tools.timestamp(), time_update=tools.timestamp(), public=1, )
def gen_passwd(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) userinfo = self.muser.get_by_id(post_data['u'][0]) sub_timestamp = int(post_data['t'][0]) cur_timestamp = tools.timestamp() if cur_timestamp - sub_timestamp < 600 and cur_timestamp > sub_timestamp: pass else: kwd = { 'info': '密码重置已超时!', } self.set_status(400) self.render('html/404.html', kwd=kwd) hash_str = tools.md5(userinfo.user_name + post_data['t'][0] + userinfo.user_pass) if hash_str == post_data['p'][0]: pass else: kwd = { 'info': '密码重置验证出错!', } self.set_status(400) self.render('html/404.html', kwd=kwd) new_passwd = tools.get_uu8d() self.muser.update_pass(userinfo.user_name, new_passwd) kwd = { 'user_name': userinfo.user_name, 'new_pass': new_passwd, } self.render('{0}/{1}/show_pass.html'.format(self.tmpl_name, self.tmpl_router), kwd=kwd)
def update(self, par_uid): if self.userinfo.privilege[2] == '1': pass else: return rec_info = self.minfo.get_by_id(par_uid) post_data = rec_info.infor for key in self.request.arguments: post_data[key] = self.get_arguments(key) ts = tools.timestamp() post_data['catname'] = self.mcat.get_by_id(post_data['catid'][0]).catname post_data['userid'] = self.userinfo.user_name post_data['def_uid'] = str(par_uid) post_data['update_time'] = ts post_data['def_update_time_str'] = time.localtime(ts) post_data['def_refresh'] = 1 post_data['def_refresh_out_time'] = ts + c.refresh_timeout post_data['def_valid'] = 1 post_data['def_banned'] = 0 post_data['keywords'] = [x.strip() for x in post_data['keywords'][0].split(',')] self.minfo.update(par_uid, post_data) self.redirect('/list/{0}'.format(post_data['catid'][0]))
def gen_passwd(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) userinfo = self.muser.get_by_id(post_data['u'][0]) sub_timestamp = int(post_data['t'][0]) cur_timestamp = tools.timestamp() if cur_timestamp - sub_timestamp < 600 and cur_timestamp > sub_timestamp: pass else: kwd = { 'info': '密码重置已超时!', } self.set_status(400) self.render('html/404.html', kwd=kwd) hash_str = tools.md5(userinfo.user_name + post_data['t'][0] + userinfo.user_pass) if hash_str == post_data['p'][0]: pass else: kwd = { 'info': '密码重置验证出错!', } self.set_status(400) self.render('html/404.html', kwd=kwd) new_passwd = tools.get_uu8d() self.muser.update_pass(userinfo.user_name, new_passwd) kwd = { 'user_name': userinfo.user_name, 'new_pass': new_passwd, } self.render('{0}/user/show_pass.html'.format(self.tmpl_name), kwd=kwd)
def reset_password(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if 'email' in post_data: userinfo = self.muser.get_by_email(post_data['email'][0]) if tools.timestamp() - userinfo.reset_passwd_timestamp < 70: self.set_status(400) kwd = { 'info': '两次重置密码时间应该大于1分钟', } self.render('html/404.html', kwd=kwd, userinfo=self.userinfo) return False if userinfo: timestamp = tools.timestamp() passwd = userinfo.user_pass username = userinfo.user_name hash_str = tools.md5(username + str(timestamp) + passwd) url_reset = '{0}/user/reset-passwd?u={1}&t={2}&p={3}'.format( config.site_url, username, timestamp, hash_str) email_cnt = ''' <div>请查看下面的信息,并<span style="color:red">谨慎操作</span>:</div> <div>您在"{0}"网站({1})申请了密码重置,如果确定要进行密码重置,请打开下面链接:</div> <div><a href={2}>{2}</a></div> <div>如果无法确定本信息的有效性,请忽略本邮件。</div> '''.format(config.site_name, config.site_url, url_reset) if send_mail([userinfo.user_email], "{0}|密码重置".format(config.site_name), email_cnt): self.muser.update_reset_passwd_timestamp( username, timestamp) self.set_status(200) return True else: self.set_status(400) return False else: self.set_status(400) return False else: self.set_status(400) return False
def reset_password(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if 'email' in post_data: userinfo = self.muser.get_by_email(post_data['email'][0]) if tools.timestamp() - userinfo.reset_passwd_timestamp < 70: self.set_status(400) kwd = { 'info': '两次重置密码时间应该大于1分钟', } self.render('html/404.html', kwd=kwd) return False if userinfo: timestamp = tools.timestamp() passwd = userinfo.user_pass username = userinfo.user_name hash_str = tools.md5(username + str(timestamp) + passwd) url_reset = '{0}/user/reset-passwd?u={1}&t={2}&p={3}'.format(config.site_url, username, timestamp, hash_str) email_cnt = ''' <div>请查看下面的信息,并<span style="color:red">谨慎操作</span>:</div> <div>您在"{0}"网站({1})申请了密码重置,如果确定要进行密码重置,请打开下面链接:</div> <div><a href={2}>{2}</a></div> <div>如果无法确定本信息的有效性,请忽略本邮件。</div> '''.format(config.site_name, config.site_url, url_reset) if send_mail([userinfo.user_email], "{0}|密码重置".format(config.site_name), email_cnt): self.muser.update_reset_passwd_timestamp(username, timestamp) self.set_status(200) return True else: self.set_status(400) return False else: self.set_status(400) return False else: self.set_status(400) return False
def add_or_update(self, uid, user_id, app_id, geojson): current_count = TabJson.select().where(TabJson.uid == uid).count() if current_count > 0: cur_record = self.get_by_id(uid) entry = TabJson.update( json=geojson, time_update=tools.timestamp(), ).where(TabJson.uid == cur_record.uid) entry.execute() else: entry = TabJson.create( uid=uid, title='', app=app_id, user=user_id, json=geojson, time_create=tools.timestamp(), time_update=tools.timestamp(), public=1, )
def add_json(self, json_uid, user_id, geojson): current_count = TabJson.select().where(TabJson.uid == json_uid).count() if current_count > 0: cur_record = self.get_by_id(json_uid) entry = TabJson.update( json=geojson, time_update=tools.timestamp(), ).where(TabJson.uid == cur_record.uid) entry.execute() else: entry = TabJson.create( uid=json_uid, title='', # app=app_id, user=user_id, json=geojson, time_create=tools.timestamp(), time_update=tools.timestamp(), public=1, )
def update(self, uid, post_data): cnt_html = tools.markdown2html(post_data['cnt_md'][0]) entry = CabWiki.update( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), ).where(CabWiki.uid == uid) entry.execute()
def insert_data(self, post_data): title = post_data['title'][0] uu = self.get_by_wiki(title) if uu is None: pass else: return (False) cnt_html = tools.markdown2html(post_data['cnt_md'][0]) entry = CabWiki.create( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, uid=tools.get_uu8d(), time_create=tools.timestamp(), user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), view_count=1, ) return (entry.uid)
def add(self): if self.userinfo.privilege[2] == '1': pass else: return post_data = { } for key in self.request.arguments: post_data[key] = self.get_arguments(key) uid = post_data['uid'][0] # 对uid进行判断,防止反复发布同一信息。 uu = self.minfo.get_by_id(uid) if uu: self.render('not_repeat.html') return False ts = tools.timestamp() post_data['catname'] = self.mcat.get_by_id(post_data['catid'][0]).catname post_data['userid'] = self.userinfo.user_name # post_data['views'] = 1 # post_data['create_time'] = ts # post_data['update_time'] = ts # 添加控制字段 post_data['def_uid'] = str(uid) post_data['def_create_time_str'] = time.localtime(ts) post_data['def_update_time_str'] = time.localtime(ts) # 记录的超时的时间 # 推广 post_data['def_tuiguang_out_time'] = ts # 置顶 post_data['def_zhiding'] = 0 post_data['def_zhiding_out_time'] = ts # 刷新 post_data['def_refresh'] = 1 post_data['def_refresh_out_time'] = ts + c.refresh_timeout # 是否有效。是否通过审核 post_data['def_valid'] = 1 post_data['def_banned'] = 0 post_data['keywords'] = [x.strip() for x in post_data['keywords'][0].split(',')] post_data['def_tuiguang'] = 0 if self.minfo.insert_data(self.userinfo.uid, post_data): self.redirect('/list/{0}'.format(post_data['catid'][0])) else: self.render('{0}/html/error.html'.format(self.template_dir_name))
def insert_data(self, post_data): uid = tools.get_uuid() try: CabReply.create( uid=uid, user_name=post_data['user_name'], create_user_id=post_data['user_id'], timestamp=tools.timestamp(), date=datetime.datetime.now(), cnt_md=post_data['cnt_md'][0], cnt_html=tools.markdown2html(post_data['cnt_md'][0]), vote=0, ) return (uid) except: return False
def update(self, uid, post_data): print(post_data["src_type"][0]) if post_data["src_type"][0] == "1": cnt_html = tools.rst2html(post_data["cnt_md"][0]) else: cnt_html = tools.markdown2html(post_data["cnt_md"][0]) entry = CabWiki.update( title=post_data["title"][0], date=datetime.datetime.now(), cnt_html=cnt_html, user_name=post_data["user_name"], cnt_md=tornado.escape.xhtml_escape(post_data["cnt_md"][0]), time_update=tools.timestamp(), src_type=post_data["src_type"][0], ).where(CabWiki.uid == uid) entry.execute()
def update(self, uid, post_data, update_time=False): if 'id_spec' in post_data: id_spec = post_data['id_spec'][0] else: id_spec = 0 if 'src_type' in post_data and post_data['src_type'][0] == '1': cnt_html = tools.rst2html(post_data['cnt_md'][0]) else: cnt_html = tools.markdown2html(post_data['cnt_md'][0]) if update_time: entry = CabReply.update( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), id_spec=id_spec, logo=post_data['logo'][0], keywords=post_data['keywords'][0], src_type=post_data['src_type'][0] if ('src_type' in post_data) else 0).where(CabReply.uid == uid) else: entry = CabReply.update( title=post_data['title'][0], cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), id_spec=id_spec, logo=post_data['logo'][0], keywords=post_data['keywords'][0], src_type=post_data['src_type'][0] if ('src_type' in post_data) else 0).where(CabReply.uid == uid) entry.execute()
def update(self, uid, post_data, update_time=False): if 'id_spec' in post_data: id_spec = post_data['id_spec'][0] else: id_spec = 0 if 'src_type' in post_data and post_data['src_type'][0] == '1': cnt_html = tools.rst2html(post_data['cnt_md'][0]) else: cnt_html = tools.markdown2html(post_data['cnt_md'][0]) if update_time: entry = CabReply.update( title=post_data['title'][0], date=datetime.datetime.now(), cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), time_update=tools.timestamp(), id_spec=id_spec, logo=post_data['logo'][0], keywords=post_data['keywords'][0], src_type=post_data['src_type'][0] if ('src_type' in post_data) else 0 ).where(CabReply.uid == uid) else: entry = CabReply.update( title=post_data['title'][0], cnt_html=cnt_html, user_name=post_data['user_name'], cnt_md=tornado.escape.xhtml_escape(post_data['cnt_md'][0]), id_spec=id_spec, logo=post_data['logo'][0], keywords=post_data['keywords'][0], src_type=post_data['src_type'][0] if ('src_type' in post_data) else 0 ).where(CabReply.uid == uid) entry.execute()