Esempio n. 1
0
 def POST(self):
     import json
     json_dict = {'success':0, 'msg':'', 'script':''}
     comment_id = web.input(comment_id=None)['comment_id']
     comment = comment_model().get_one({'id':comment_id})
     if comment_id and comment:
         if session.user_id is None:
             post = post_model().get_one({'id':comment.post_id})
             json_dict['msg'] = '你要先登录的亲'
             json_dict['script'] = 'location.href=\'/login?next=/post/'+str(post.id)+'#reply-'+str(comment_id)+'\''
         elif comment.user_id != session.user_id:
             comment_thanks_id = comment_thanks_model().unique_insert({'user_id':session.user_id, 'comment_id':comment_id})
             if comment_thanks_id:
                 comment_thanks_model().update({'id':comment_thanks_id}, {'time':int(time.time())})
                 cost = money_model().cal_thanks()
                 money_type_id = money_type_model().get_one({'name':'comment_thanks'})['id']
                 money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':comment_thanks_id})
                 money_model().insert({'user_id':comment.user_id, 'money_type_id':money_type_id, 'amount':cost, 'foreign_id':comment_thanks_id, 'balance':user_model().update_money(comment.user_id, cost)})
                 comment_model().count_thanks(comment_id)
                 user_model().update_session(session.user_id)
                 json_dict['success'] = 1
             else:
                 json_dict['msg'] = '你已经感谢过了不是吗?'
         else:
             json_dict['msg'] = '你不能感谢你自己不是吗?'
     else:
         json_dict['message'] = '评论不存在'
     return json.dumps(json_dict)
Esempio n. 2
0
 def GET(self):
 	title = '首页'
     #sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     #post_ids = post_model().query_result(sql)
     post_results = post_model().get_all(order='last_update DESC', limit=20)
     posts = []
     for post_result in post_results:
         #post_result = post_model().get_one({'id':row.post_id})
         post = {'post':post_result}
         user = user_model().get_one({'id':post_result.user_id})
         post['user'] = user
         node = node_model().get_one({'id':post_result.node_id})
         post['node'] = node
         comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
         if comment:
             comment_user = user_model().get_one({'id':comment.user_id})
             post['comment_user'] = comment_user
         else:
             post['comment_user'] = None
         posts.append(post)
     cats_result = cat_model().get_all()
     cats = []
     for cat_result in cats_result:
         cat = {'cat':cat_result}
         node = node_model().get_all({'category_id':cat_result.id})
         cat['node'] = node
         cats.append(cat)
     return render.index(cats, posts, title)
Esempio n. 3
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login')
     post = post_model().get_one({'id':post_id})
     if post is not None:
         if not self.form.validates():
             raise web.SeeOther('/post/' + post_id)
         else:
             user_model().update_session(session.user_id)
             length, cost = money_model().cal_comment(self.form.d.content)
             if session.money < cost:
                 self.crumb.append('财富不够')
                 return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
             content = html2db(self.form.d.content)
             content, receiver_list = notify_model().convert_content(content)
             create_time = time.time()
             comment_id = comment_model().insert({'user_id' : session.user_id, 'post_id' : post_id, 'content' : content, 'time' : create_time})
             money_type_id = money_type_model().get_one({'name':'comment'})['id']
             money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':comment_id})
             if session.user_id != post.user_id:
                 money_model().insert({'user_id':post.user_id, 'money_type_id':money_type_id, 'amount':cost, 'length':length, 'foreign_id':comment_id, 'balance':user_model().update_money(post.user_id, cost)})
                 # notify
                 notify_model().insert({'user_id':session.user_id, 'receiver':post.user_id, 'type_id':notify_type_model().get_one({'name':'comment'}).id, 'foreign_id':comment_id})
             # notify
             receiver_list = list_diff(receiver_list, [session.name, user_model().get_one({'id':post.user_id}).name])
             notify_model().insert_notify(session.user_id, receiver_list, 'comment_at', comment_id)
             user_model().update_session(session.user_id)
             post_model().update({'id':post_id}, {'last_update':create_time})
             post_model().count_comment(post_id)
             raise web.SeeOther('/post/' + post_id)
     else:
          raise web.SeeOther('/post/' + post_id)
Esempio n. 4
0
 def GET(self, name):
     limit = 10
     user = user_model().get_one({'name': name})
     crumb = Crumb()
     if user:
         crumb.append(name, '/profile/' + name)
         crumb.append('全部回复')
         total = comment_model().count_table({'user_id': user.id})
         pagination = Pagination('/profile/' + name + '/comments',
                                 total,
                                 limit=limit)
         page = pagination.true_page(web.input(p=1)['p'])
         comments_result = comment_model().get_all({'user_id': user.id},
                                                   limit=limit,
                                                   offset=(page - 1) *
                                                   limit,
                                                   order='time DESC')
         if len(comments_result) > 0:
             comments = []
             for comment_result in comments_result:
                 post = post_model().get_one({'id': comment_result.post_id})
                 post_user = user_model().get_one({'id': post.user_id})
                 comment = {
                     'post': post,
                     'comment': comment_result,
                     'post_user': post_user
                 }
                 comments.append(comment)
         else:
             comments = None
         return render.user_comments('全部回复', comments, total,
                                     crumb.output(), pagination.output())
     else:
         crumb.append('会员未找到')
         return render.user_nf('会员未找到', crumb.output())
Esempio n. 5
0
 def GET(self):
     limit = 10
     self.crumb.append('我关注的人的最新主题')
     # 取出收藏的节点id
     followings = user_meta_model().get_all({'user_id':session.user_id, 'meta_key':'follow'})
     if len(followings) > 0 :
        user_favs = []
        for following in followings:
            user_favs.append(following.meta_value)
        total_rows = post_model().count_table({'user_id':user_favs})
        pagination = Pagination('/my/following', total_rows, limit = limit)
        page = pagination.true_page(web.input(p=1)['p'])
        posts_result = post_model().get_all(conditions = {'user_id': user_favs}, order = 'time DESC', limit = limit, offset = (page-1)*limit)
        posts = []
        for post_result in posts_result:
            post = {'post':post_result}
            user = user_model().get_one({'id':post_result.user_id})
            post['user'] = user
            node = node_model().get_one({'id':post_result.node_id})
            post['node'] = node
            comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
            if comment:
                comment_user = user_model().get_one({'id':comment.user_id})
                post['comment_user'] = comment_user
            else:
                post['comment_user'] = None
            posts.append(post)
     else:
        posts = None
        total_rows = 0
        pagination = Pagination('/my/nodes', total_rows)
        page = pagination.true_page(web.input(p=1)['p'])
     return render.following_posts('来自我收藏的节点的最新主题', posts, total_rows, self.crumb.output(), pagination.output())
Esempio n. 6
0
 def GET(self, post_id):
     if session.user_id is None:
             raise web.SeeOther('/login?next=/post/unfav/'+post_id)
     user_meta_model().delete({'user_id':session.user_id, 'meta_key':'post_fav','meta_value':post_id})
     user_model().update({'id':session.user_id}, {'post_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'post_fav'})})
     user_model().update_session(session.user_id)
     raise web.SeeOther('/post/'+post_id)
Esempio n. 7
0
 def GET(self):
     # sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     # post_ids = post_model().query_result(sql)
     crumb = Crumb()
     limit = 50
     total = post_model().count_table()
     pagination = Pagination("/recent", total, limit=limit)
     page = pagination.true_page(web.input(p=1)["p"])
     post_results = post_model().get_all(limit=limit, offset=(page - 1) * limit, order="time DESC")
     posts = []
     for post_result in post_results:
         # post_result = post_model().get_one({'id':row.post_id})
         post = {"post": post_result}
         user = user_model().get_one({"id": post_result.user_id})
         post["user"] = user
         node = node_model().get_one({"id": post_result.node_id})
         post["node"] = node
         comment = comment_model().get_one({"post_id": post_result.id}, order="time DESC")
         if comment:
             comment_user = user_model().get_one({"id": comment.user_id})
             post["comment_user"] = comment_user
         else:
             post["comment_user"] = None
         posts.append(post)
     crumb.append("最近的主题")
     return render.recent("最近的主题", total, crumb.output(), posts, pagination.output())
Esempio n. 8
0
 def POST(self):
     if not self.form.validates():
         return render.signup(self.form, '注册失败,请重注', self.crumb.output())
     try:
         condition = {'name': self.form.d.name}
         user = user_model().get_one(condition)
         # 对密码进行 md5 加密
         auth = string.join(
             random.sample([
                 'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o',
                 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c',
                 'b', 'a'
             ], 5)).replace(' ', '')
         password = hashlib.md5(
             hashlib.md5(self.form.d.password).hexdigest() +
             auth).hexdigest()
         #password = hashlib.md5(self.form.d.password).hexdigest()
         if user is not None:
             raise ValueExistsError('用户名已经存在')
         condition = {'email': self.form.d.email}
         user = user_model().get_one(condition)
         if user is not None:
             raise ValueExistsError('邮箱已经存在')
         user_model().insert({
             'name': self.form.d.name,
             'email': self.form.d.email,
             'password': password,
             'regist_time': time.time(),
             'auth': auth
         })
     except ValueExistsError, x:
         return render.signup(self.form, x.message, self.crumb.output())
Esempio n. 9
0
 def GET(self, post_id):
     if session.user_id is None:
             raise web.SeeOther('/login?next=/post/unfav/'+post_id)
     user_meta_model().delete({'user_id':session.user_id, 'meta_key':'post_fav','meta_value':post_id})
     user_model().update({'id':session.user_id}, {'post_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'post_fav'})})
     user_model().update_session(session.user_id)
     raise web.SeeOther('/post/'+post_id)
Esempio n. 10
0
 def GET(self):
     title = '首页'
     #sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     #post_ids = post_model().query_result(sql)
     post_results = post_model().get_all(order='last_update DESC', limit=20)
     posts = []
     for post_result in post_results:
         #post_result = post_model().get_one({'id':row.post_id})
         post = {'post': post_result}
         user = user_model().get_one({'id': post_result.user_id})
         post['user'] = user
         node = node_model().get_one({'id': post_result.node_id})
         post['node'] = node
         comment = comment_model().get_one({'post_id': post_result.id},
                                           order='time DESC')
         if comment:
             comment_user = user_model().get_one({'id': comment.user_id})
             post['comment_user'] = comment_user
         else:
             post['comment_user'] = None
         posts.append(post)
     cats_result = cat_model().get_all()
     cats = []
     for cat_result in cats_result:
         cat = {'cat': cat_result}
         node = node_model().get_all({'category_id': cat_result.id})
         cat['node'] = node
         cats.append(cat)
     return render.index(cats, posts, title)
Esempio n. 11
0
 def GET(self):
     limit = 10
     self.crumb.append('我收藏的主题')
     user = user_model().get_one({'id':session.user_id})
     pagination = Pagination('/my/posts', user.post_favs, limit = limit)
     if user.post_favs > 0:
         page = pagination.true_page(web.input(p=1)['p'])
         post_favs = user_meta_model().get_all({'user_id':user.id, 'meta_key':'post_fav'}, limit = limit, offset = (page-1)*limit, order = 'id DESC')
         posts = []
         for post_fav in post_favs:
             post_result = post_model().get_one({'id':post_fav.meta_value})
             post = {'post':post_result}
             user = user_model().get_one({'id':post_result.user_id})
             post['user'] = user
             node = node_model().get_one({'id':post_result.node_id})
             post['node'] = node
             comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
             if comment:
                 comment_user = user_model().get_one({'id':comment.user_id})
                 post['comment_user'] = comment_user
             else:
                 post['comment_user'] = None
             posts.append(post)
     else:
         posts = None
     return render.post_favs('我收藏的主题', user, posts, self.crumb.output(), pagination.output())
Esempio n. 12
0
 def POST(self):
     self.crumb.append('设置', '/settings')
     self.crumb.append('修改密码')
     user = user_model().get_one({'id': session.user_id})
     if self.form.validates():
         password = hashlib.md5(
             hashlib.md5(self.form.d.origin_password).hexdigest() +
             user.auth).hexdigest()
         if user.password == password:
             auth = string.join(
                 random.sample([
                     'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p',
                     'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e',
                     'd', 'c', 'b', 'a'
                 ], 5)).replace(' ', '')
             new_password = hashlib.md5(
                 hashlib.md5(self.form.d.new_password).hexdigest() +
                 auth).hexdigest()
             user_model().update({'id': user.id}, {
                 'password': new_password,
                 'auth': auth
             })
             raise web.SeeOther('/settings')
         else:
             return render.password('原密码不正确', self.crumb.output(),
                                    self.form)
     else:
         return render.password('修改密码', self.crumb.output(), self.form)
Esempio n. 13
0
 def GET(self, name):
     limit = 10
     user = user_model().get_one({'name':name})
     crumb = Crumb()
     if user:
         crumb.append(name, '/profile/'+name)
         crumb.append('全部主题')
         total_rows = post_model().count_table({'user_id':user.id})
         pagination = Pagination('/profile/'+name+'/posts', total_rows, limit = limit)
         page = pagination.true_page(web.input(p=1)['p'])
         posts_result = post_model().get_all({'user_id':user.id}, limit = limit, offset = (page-1) * limit, order = 'time DESC')
         posts = []
         for post_result in posts_result:
             post = {'post':post_result}
             node = node_model().get_one({'id':post_result.node_id})
             post['node'] = node
             comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
             if comment:
                 comment_user = user_model().get_one({'id':comment.user_id})
                 post['comment_user'] = comment_user
             else:
                 post['comment_user'] = None
             posts.append(post)
         return render.user_posts('全部主题', user,  posts, total_rows, crumb.output(), pagination.output())
     else:
         crumb.append('会员未找到')
         return render.user_nf('会员未找到', crumb.output())
Esempio n. 14
0
 def GET(self, node_name):
     limit = 10
     node = node_model().get_one({'name': node_name})
     if node is None:
         self.crumb.append('节点未找到')
         return render.node_nf('节点未找到', self.crumb.output())
     else:
         self.crumb.append(node.display_name)
         node_fav = False
         if session.user_id:
             if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id}):
                 node_fav = True
         total_rows = post_model().count_table({'node_id':node.id})
         pagination = Pagination('/node/'+node_name, total_rows, limit = limit)
         page = pagination.true_page(web.input(p=1)['p'])
         posts_result = post_model().get_all({'node_id' : node.id}, limit = limit, offset = (page-1)*limit , order = 'time DESC')
         posts = []
         for post_result in posts_result:
             post = {'post':post_result}
             user = user_model().get_one({'id':post_result.user_id})
             post['user'] = user
             comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
             if comment:
                 comment_user = user_model().get_one({'id':comment.user_id})
                 post['comment_user'] = comment_user
             else:
                 post['comment_user'] = None
             posts.append(post)
         return render.node_posts(posts, node, total_rows, node_fav, self.crumb.output(), pagination.output())
Esempio n. 15
0
 def GET(self):
     #sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
     #post_ids = post_model().query_result(sql)
     crumb = Crumb()
     limit = 50
     total = post_model().count_table()
     pagination = Pagination('/recent', total, limit=limit)
     page = pagination.true_page(web.input(p=1)['p'])
     post_results = post_model().get_all(limit=limit,
                                         offset=(page - 1) * limit,
                                         order='time DESC')
     posts = []
     for post_result in post_results:
         #post_result = post_model().get_one({'id':row.post_id})
         post = {'post': post_result}
         user = user_model().get_one({'id': post_result.user_id})
         post['user'] = user
         node = node_model().get_one({'id': post_result.node_id})
         post['node'] = node
         comment = comment_model().get_one({'post_id': post_result.id},
                                           order='time DESC')
         if comment:
             comment_user = user_model().get_one({'id': comment.user_id})
             post['comment_user'] = comment_user
         else:
             post['comment_user'] = None
         posts.append(post)
     crumb.append('最近的主题')
     return render.recent('最近的主题', total, crumb.output(), posts,
                          pagination.output())
Esempio n. 16
0
 def POST(self):
     import json
     json_dict = {'success':0, 'msg':'', 'script':''}
     post_id = web.input(post_id=None)['post_id']
     post = post_model().get_one({'id':post_id})
     if post_id and post:
         if session.user_id is None:
             json_dict['msg'] = '你要先登录的亲'
             json_dict['script'] = 'location.href=\'/login?next=/post/'+post.id+'\''
         elif post.user_id != session.user_id:
             post_thanks_id = post_thanks_model().unique_insert({'user_id':session.user_id, 'post_id':post_id})
             if post_thanks_id:
                 post_thanks_model().update({'id':post_thanks_id}, {'time':int(time.time())})
                 cost = money_model().cal_thanks()
                 money_type_id = money_type_model().get_one({'name':'post_thanks'})['id']
                 money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':post_thanks_id})
                 money_model().insert({'user_id':post.user_id, 'money_type_id':money_type_id, 'amount':cost, 'foreign_id':post_thanks_id, 'balance':user_model().update_money(post.user_id, cost)})
                 post_model().count_thanks(post_id)
                 user_model().update_session(session.user_id)
                 json_dict['success'] = 1
             else:
                 json_dict['msg'] = '你已经感谢过了不是吗?'
         else:
             json_dict['msg'] = '你不能感谢你自己不是吗?'
     else:
         json_dict['message'] = '评论不存在'
     return json.dumps(json_dict)
Esempio n. 17
0
 def POST(self, node_name):
     if session.user_id is None:
         raise web.SeeOther('/login?next=/post/create' + node_name)
     conditions = {'name' : node_name}
     node = node_model().get_one(conditions)
     if node is None:
         return render.not_found('节点未找到', '节点未找到')
     if not self.form.validates():
         return render.create_post(self.form, '创建失败, 请重创:D', self.crumb.output())
     user_model().update_session(session.user_id)
     length, cost = money_model().cal_post(self.form.d.content)
     if session.money < cost:
         self.crumb.append('财富不够')
         return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
     title = strip_tags(self.form.d.title)
     content = html2db(self.form.d.content)
     content, receiver_list = notify_model().convert_content(content)
     create_time = time.time()
     post_id = post_model().insert({'title' : title, 'content' : content, 'node_id' : node.id, 'time' : create_time, 'last_update':create_time, 'user_id' : session.user_id})
     # money
     money_type_id = money_type_model().get_one({'name':'post'})['id']
     money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':post_id})
     # notify
     receiver_list = list_diff(receiver_list, [session.name])
     notify_model().insert_notify(session.user_id, receiver_list, 'post_at', post_id)
     user_model().update_session(session.user_id)
     raise web.seeother('/post/' + str(post_id))
Esempio n. 18
0
 def GET(self, node_name):
     node = node_model().get_one({'name': node_name})
     if node is None:
         self.crumb.append('节点未找到')
         return render.node_nf('节点未找到', self.crumb.output())
     if session.user_id is None:
         raise web.SeeOther('/login?next=/node/'+node_name)
     user_meta_model().delete({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id})
     user_model().update({'id':session.user_id}, {'node_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'node_fav'})})
     user_model().update_session(session.user_id)
     raise web.SeeOther('/node/'+node_name)
Esempio n. 19
0
 def GET(self, node_name):
     node = node_model().get_one({'name': node_name})
     if node is None:
         self.crumb.append('节点未找到')
         return render.node_nf('节点未找到', self.crumb.output())
     if session.user_id is None:
         raise web.SeeOther('/login?next=/node/'+node_name)
     user_meta_model().delete({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id})
     user_model().update({'id':session.user_id}, {'node_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'node_fav'})})
     user_model().update_session(session.user_id)
     raise web.SeeOther('/node/'+node_name)
Esempio n. 20
0
 def GET(self, post_id):
     post = post_model().get_one({'id':post_id})
     if post is None:
         self.crumb.append('主题未找到')
         return render.post_nf('主题未找到', self.crumb.output())
     if session.user_id is None:
         raise web.SeeOther('/login?next=/post/fav/'+post_id)
     user_meta_model().unique_insert({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post_id})
     user_model().update({'id':session.user_id}, {'post_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'post_fav'})})
     user_model().update_session(session.user_id)
     raise web.SeeOther('/post/' + post_id)
Esempio n. 21
0
 def GET(self, post_id):
     post = post_model().get_one({'id':post_id})
     if post is None:
         self.crumb.append('主题未找到')
         return render.post_nf('主题未找到', self.crumb.output())
     if session.user_id is None:
         raise web.SeeOther('/login?next=/post/fav/'+post_id)
     user_meta_model().unique_insert({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post_id})
     user_model().update({'id':session.user_id}, {'post_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'post_fav'})})
     user_model().update_session(session.user_id)
     raise web.SeeOther('/post/' + post_id)
Esempio n. 22
0
 def GET(self, name):
     limit = 10
     user = user_model().get_one({'name': name})
     if user is None:
         crumb = Crumb()
         crumb.append('会员未找到')
         return render.user_nf('会员未找到', crumb.output())
     else:
         posts_result = post_model().get_all({'user_id': user.id},
                                             limit=limit,
                                             order='time DESC')
         if len(posts_result) > 0:
             posts = []
             for post_result in posts_result:
                 post = {'post': post_result}
                 node = node_model().get_one({'id': post_result.node_id})
                 post['node'] = node
                 comment = comment_model().get_one(
                     {'post_id': post_result.id}, order='time DESC')
                 if comment:
                     comment_user = user_model().get_one(
                         {'id': comment.user_id})
                     post['comment_user'] = comment_user
                 else:
                     post['comment_user'] = None
                 posts.append(post)
         else:
             posts = None
         comments_result = comment_model().get_all({'user_id': user.id},
                                                   limit=limit,
                                                   order='time DESC')
         if len(comments_result) > 0:
             comments = []
             for comment_result in comments_result:
                 post = post_model().get_one({'id': comment_result.post_id})
                 post_user = user_model().get_one({'id': post.user_id})
                 comment = {
                     'post': post,
                     'comment': comment_result,
                     'post_user': post_user
                 }
                 comments.append(comment)
         else:
             comments = None
         following = False
         if session.user_id:
             if user_meta_model().get_one({
                     'user_id': session.user_id,
                     'meta_key': 'follow',
                     'meta_value': user.id
             }):
                 following = True
         return render.profile(user.name, user, posts, comments, following)
Esempio n. 23
0
 def GET(self, name):
     user = user_model().get_one({'name':name})
     if user is None:
         crumb = Crumb()
         crumb.append('会员未找到')
         return render.user_nf('会员未找到', crumb.output())
     else:
         if session.user_id is None:
             raise web.SeeOther('/login?next=/profile/'+name)
         user_meta_model().delete({'user_id':session.user_id, 'meta_key':'follow', 'meta_value':user.id})
         user_model().update({'id':session.user_id}, {'user_favs':user_meta_model().count_meta({'user_id':session.user_id, 'meta_key':'follow'})})
         user_model().update_session(session.user_id)
         raise web.SeeOther('/profile/'+name)
Esempio n. 24
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login?next=/edit/post/' + post_id)
     conditions = {'id': int(post_id)}
     post = post_model().get_one(conditions)
     if post is None:
         return render.not_found('节点未找到', '节点未找到')
     if not self.form.validates():
         return render.create_post(self.form, '创建失败, 请重创:D',
                                   self.crumb.output())
     user_model().update_session(session.user_id)
     length, cost = money_model().cal_post(self.form.d.content)
     if session.money < cost:
         self.crumb.append('财富不够')
         return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(',
                                self.crumb.output())
     title = strip_tags(self.form.d.title)
     content = html2db(self.form.d.content)
     content, receiver_list = notify_model().convert_content(content)
     create_time = time.time()
     post_model().update({'id': int(post_id)}, {
         'title': title,
         'content': content,
         'node_id': post.node_id,
         'time': create_time,
         'last_update': create_time,
         'user_id': session.user_id
     })
     # money
     money_type_id = money_type_model().get_one({'name': 'post'})['id']
     money_model().insert({
         'user_id':
         session.user_id,
         'money_type_id':
         money_type_id,
         'amount':
         -cost,
         'length':
         length,
         'balance':
         user_model().update_money(session.user_id, -cost),
         'foreign_id':
         post_id
     })
     # notify
     receiver_list = list_diff(receiver_list, [session.name])
     notify_model().insert_notify(session.user_id, receiver_list, 'post_at',
                                  post_id)
     user_model().update_session(session.user_id)
     raise web.seeother('/post/' + str(post_id))
Esempio n. 25
0
 def POST(self):
     self.crumb.append('设置')
     user = user_model().get_one({'id':session.user_id})
     self.setting_form.name.set_value(user.name)
     if not self.setting_form.validates():
         self.setting_form.name.set_value(user.name)
         self.setting_form.email.set_value(user.email)
         self.setting_form.email.set_value(user.signature)
         self.setting_form.email.set_value(user.outsite_link)
         return render.settings('设置', user, self.setting_form, self.pass_form, self.crumb.output())
     else:
         user_model().update({'id':user.id}, {'email':self.setting_form.d.email, 'signature':self.setting_form.d.signature, 'outsite_link':self.setting_form.d.outsite_link.replace('http://', '').replace('https://', '')})
         
         raise web.SeeOther('/settings')
Esempio n. 26
0
 def GET(self):
     limit = 20
     total = money_model().count_table({'user_id':session.user_id})
     pagination = Pagination('/balance', total, limit = limit)
     page = pagination.true_page(web.input(p=1)['p'])
     records_result = money_model().get_all({'user_id':session.user_id}, limit = limit, offset = (page-1)*limit, order = 'id DESC')
     money_types_result = money_type_model().get_all()
     money_type = {}
     for money_type_result in money_types_result:
         money_type[money_type_result.id] = money_type_result.name
     records = []
     for record_result in records_result:
         # 发布的帖子或者是评论的帖子
         post = None
         # 发布或者收到的评论
         post_user = None
         post_thanks = None
         comment_thanks = None
         sender = None
         comment = None
         # 评论的用户
         comment_user = None
         try:
             type = money_type[record_result.money_type_id]
             if type == 'post':
                 post = post_model().get_one({'id':record_result.foreign_id})
             if type == 'comment':
                 comment = comment_model().get_one({'id':record_result.foreign_id})
                 comment_user = user_model().get_one({'id':comment.user_id})
                 post = post_model().get_one({'id':comment.post_id})
             if type == 'post_thanks':
                 post_thanks = post_thanks_model().get_one({'id':record_result.foreign_id})
                 post = post_model().get_one({'id':post_thanks.post_id})
                 sender = user_model().get_one({'id':post_thanks.user_id})
                 post_user = user_model().get_one({'id':post.user_id})
             if type == 'comment_thanks':
                 comment_thanks = comment_thanks_model().get_one({'id':record_result.foreign_id})
                 comment = comment_model().get_one({'id':comment_thanks.comment_id})
                 post = post_model().get_one({'id':comment.post_id})
                 comment_user = user_model().get_one({'id':comment.user_id})
                 sender = user_model().get_one({'id':comment_thanks.user_id})
         # 如果数据错误将不把这条记录输出到视图
         except AttributeError:
             continue
         else:
             record = {'record':record_result, 'type':type, 'comment':comment, 'post':post, 'post_user':post_user, 'sender':sender, 'comment_user':comment_user, 'post_thanks':post_thanks, 'comment_thanks':comment_thanks}
             records.append(record)
     self.crumb.append('账户余额')
     return render.money_record('账户余额', records, self.crumb.output(), pagination.output())
Esempio n. 27
0
 def POST(self):
     self.crumb.append('设置', '/settings')
     self.crumb.append('修改密码')
     user = user_model().get_one({'id':session.user_id})
     if self.form.validates():
         password = hashlib.md5(hashlib.md5(self.form.d.origin_password).hexdigest() + user.auth).hexdigest()
         if user.password == password:
             auth = string.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5)).replace(' ','')
             new_password = hashlib.md5(hashlib.md5(self.form.d.new_password).hexdigest() + auth).hexdigest()
             user_model().update({'id':user.id}, {'password':new_password, 'auth':auth})
             raise web.SeeOther('/settings')
         else:
             return render.password('原密码不正确', self.crumb.output(), self.form)
     else:
         return render.password('修改密码', self.crumb.output(), self.form)
Esempio n. 28
0
 def __init__(self):
     if session.user_id:
         raise web.SeeOther('/')
     self.title = '登录'
     self.crumb = Crumb()
     self.crumb.append('登录')
     self.form = user_model().login_form
Esempio n. 29
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'

        user = users.get_current_user()

        if user:
            url = users.create_logout_url('/')
            url_string = 'Logout'
            disabled = ''
            myuser_key = ndb.Key('user_model', user.user_id())
            myuser = myuser_key.get()

            if myuser == None:
                myuser = user_model(id = user.user_id())
                myuser.username = user.email()
                myuser.put()

        else:
            url = users.create_login_url('/')
            url_string = 'Login'
            disabled = 'disabled'

        template_values = { 
            'url': url,
            'url_string': url_string,
            'user': user,
            'disabled': disabled
            }

        template = JINJA_ENVIRONMENT.get_template('main.html')
        self.response.write(template.render(template_values))
Esempio n. 30
0
 def GET(self):
     crumb = Crumb()
     condition = {"receiver": session.user_id}
     total = notify_model().count_table(condition)
     limit = 10
     pagination = Pagination("/notifications", total, limit=limit)
     page = pagination.true_page(web.input(p=1)["p"])
     notify_result = notify_model().get_all(condition, order="id DESC", limit=limit, offset=(page - 1) * limit)
     notifications = []
     if notify_result is not None:
         for notify in notify_result:
             post = None
             user = None
             comment = None
             notify_type = notify_type_model().get_one({"id": notify.type_id}).name
             user = user_model().get_one({"id": notify.user_id})
             if notify_type == "post_at":
                 post = post_model().get_one({"id": notify.foreign_id})
             elif notify_type == "comment" or notify_type == "comment_at":
                 comment = comment_model().get_one({"id": notify.foreign_id})
                 post = post_model().get_one({"id": comment.post_id})
             notifications.append(
                 {"notify": notify, "post": post, "user": user, "comment": comment, "type": notify_type}
             )
     notify_model().mark_as_read(session.user_id)
     crumb.append("提醒系统")
     return render.notify("提醒系统", crumb.output(), total, notifications, pagination.output())
Esempio n. 31
0
 def _post(self):
     if not self.form.validates():
         return False, '登录失败,请重登'
     condition = {'name' : self.form.d.name}
     # MD5加密 密码
     #condition['password'] = hashlib.md5(condition['password']).hexdigest()
     user = user_model().get_one(condition)
     if user is None:
         return False, '用户不存在'
     auth_from_form = hashlib.md5(hashlib.md5(self.form.d.password).hexdigest() + user.auth).hexdigest()
     if auth_from_form != user.password:
         return False, '密码错误'
     user_model().update_session(user.id)
     user_model().set_cookie(user.id)
     data = web.input();
     return True, ''
Esempio n. 32
0
 def GET(self):
     self.crumb.append('设置')
     user = user_model().get_one({'id':session.user_id})
     self.setting_form.name.set_value(user.name)
     self.setting_form.email.set_value(user.email)
     self.setting_form.signature.set_value(user.signature)
     self.setting_form.outsite_link.set_value(user.outsite_link)
     return render.settings('设置', user, self.setting_form, self.pass_form, self.crumb.output())
Esempio n. 33
0
 def GET(self, method):
     if method.lower() == 'signin':
         if session.user_id is None:
             return json.dumps({'ret':False, 'msg':'未登录'})
         gain = random.randint(1, 100)
         money_type_id = 7#money_type_model().get_one({'name':'post'})['id']
         balance = user_model().update_money(session.user_id, gain)
         money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':gain, 'length':0, 'balance': balance, 'foreign_id':0})
         return json.dumps({'ret':True, 'info':{'account':balance, 'gain':gain}})
Esempio n. 34
0
 def _post(self):
     if not self.form.validates():
         return False, '注册失败,请重注'
     try:
         condition = {'name':self.form.d.name}
         user = user_model().get_one(condition)
         # 对密码进行 md5 加密
         auth = string.join(random.sample(['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a'], 5)).replace(' ','')
         password = hashlib.md5(hashlib.md5(self.form.d.password).hexdigest() + auth).hexdigest()
         #password = hashlib.md5(self.form.d.password).hexdigest()
         if user is not None:
             raise ValueExistsError('用户名已经存在')
         condition = {'email' : self.form.d.email}
         user = user_model().get_one(condition)
         if user is not None:
             raise ValueExistsError('邮箱已经存在')
         user_model().insert({'name' : self.form.d.name, 'email' : self.form.d.email, 'password' : password, 'regist_time' : time.time(), 'auth' : auth})
     except ValueExistsError, x:
         return False, x.message
Esempio n. 35
0
 def POST(self):
     import cgi
     import os
     cgi.maxlen = 2 * 1024 * 1024 # 2MB
     try:
         x = web.input(avatar={})
     except ValueError:
         return render.avatar('上传头像', self.user, self.crumb.output(), ' <<超过大小限制')
     if 'avatar' in x:
         #客户端为windows时注意
         filepath=x.avatar.filename.replace('\\','/')
         #获取文件名
         filename=filepath.split('/')[-1]
         #获取后缀
         if filename == '':
             ext = ''
         else:
             ext = filename.split('.', 1)[1].lower()
         ext_allow = ('jpg', 'png', 'gif', 'jpeg')
         #判断文件后缀名 
         if ext in ext_allow:
             #要上传的路径
             filedir = 'static/avatar/tmp/'
             try:
                 os.makedirs('static/avatar/tmp')
             except:
                 pass
             filename = str(session.user_id) +'.'+ext
             if os.path.exists(filedir+filename):
                 os.remove(filedir+filename)
             fout = open(filedir + filename, 'wb')
             fout.write(x.avatar.file.read())
             fout.close()
             user_model().set_avatar(filename, self.user.id)
             error = False
         else:
             message = ' <<请上传指定格式文件'
             error = True
     if error:
         return render.avatar('上传头像', self.user, self.crumb.output(), message)
     else:
         raise web.SeeOther('/settings/avatar')
Esempio n. 36
0
 def insert_notify(self, user_id, user_list, notify_type, foreign_id):
     if isinstance(user_list, list):
         for receiver in user_list:
             user = user_model().get_one({'name': receiver})
             if user is not None:
                 self.insert({
                     'user_id': user_id,
                     'receiver': user.id,
                     'type_id': self.types[notify_type],
                     'foreign_id': foreign_id
                 })
     else:
         user = user_model().get_one({'name': user_list})
         if user is not None:
             self.insert({
                 'user_id': user_id,
                 'receiver': user.id,
                 'type_id': self.types[notify_type],
                 'foreign_id': foreign_id
             })
Esempio n. 37
0
 def GET(self, node_name):
     limit = 10
     node = node_model().get_one({'name': node_name})
     if node is None:
         self.crumb.append('节点未找到')
         return render.node_nf('节点未找到', self.crumb.output())
     else:
         self.crumb.append(node.display_name)
         node_fav = False
         if session.user_id:
             if user_meta_model().get_one({
                     'user_id': session.user_id,
                     'meta_key': 'node_fav',
                     'meta_value': node.id
             }):
                 node_fav = True
         total_rows = post_model().count_table({'node_id': node.id})
         pagination = Pagination('/node/' + node_name,
                                 total_rows,
                                 limit=limit)
         page = pagination.true_page(web.input(p=1)['p'])
         posts_result = post_model().get_all({'node_id': node.id},
                                             limit=limit,
                                             offset=(page - 1) * limit,
                                             order='time DESC')
         posts = []
         for post_result in posts_result:
             post = {'post': post_result}
             user = user_model().get_one({'id': post_result.user_id})
             post['user'] = user
             comment = comment_model().get_one({'post_id': post_result.id},
                                               order='time DESC')
             if comment:
                 comment_user = user_model().get_one(
                     {'id': comment.user_id})
                 post['comment_user'] = comment_user
             else:
                 post['comment_user'] = None
             posts.append(post)
         return render.node_posts(posts, node, total_rows, node_fav,
                                  self.crumb.output(), pagination.output())
Esempio n. 38
0
 def run(self):
     ltime = time.localtime(time.time())
     time_start = int(time.mktime(datetime.datetime(ltime.tm_year, ltime.tm_mon, ltime.tm_mday).timetuple()))
     time_end = time_start + 24 * 60 * 60
     sql = 'SELECT `post_id` FROM comment WHERE `time` >= '+str(time_start)+' AND `time` <= '+str(time_end)+' GROUP BY post_id ORDER BY count(post_id) DESC LIMIT 10'
     post_ids = comment_model().query_result(sql)
     posts = []
     for row in post_ids:
         post = post_model().get_one({'id':row.post_id})
         user = user_model().get_one({'id':post.user_id})
         posts.append({'post':post, 'user':user})
     return render.hot_posts_tody(posts)
Esempio n. 39
0
 def POST(self, post_id):
     if session.user_id is None:
         raise web.SeeOther('/login')
     post = post_model().get_one({'id': post_id})
     if post is not None:
         if not self.form.validates():
             raise web.SeeOther('/post/' + post_id)
         else:
             user_model().update_session(session.user_id)
             length, cost = money_model().cal_comment(self.form.d.content)
             if session.money < cost:
                 self.crumb.append('财富不够')
                 return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(',
                                        self.crumb.output())
             content = html2db(self.form.d.content)
             create_time = time.time()
             comment_id = comment_model().insert({
                 'user_id': session.user_id,
                 'post_id': post_id,
                 'content': content,
                 'time': create_time
             })
             money_type_id = money_type_model().get_one({'name':
                                                         'comment'})['id']
             money_model().insert({
                 'user_id':
                 session.user_id,
                 'money_type_id':
                 money_type_id,
                 'amount':
                 -cost,
                 'length':
                 length,
                 'balance':
                 user_model().update_money(session.user_id, -cost),
                 'foreign_id':
                 comment_id
             })
             if session.user_id != post.user_id:
                 money_model().insert({
                     'user_id':
                     post.user_id,
                     'money_type_id':
                     money_type_id,
                     'amount':
                     cost,
                     'length':
                     length,
                     'foreign_id':
                     comment_id,
                     'balance':
                     user_model().update_money(post.user_id, cost)
                 })
             user_model().update_session(session.user_id)
             post_model().update({'id': post_id},
                                 {'last_update': create_time})
             post_model().count_comment(post_id)
             raise web.SeeOther('/post/' + post_id)
     else:
         raise web.SeeOther('/post/' + post_id)
Esempio n. 40
0
 def GET(self, name):
     limit = 10
     user = user_model().get_one({'name':name})
     if user is None:
         crumb = Crumb()
         crumb.append('会员未找到')
         return render.user_nf('会员未找到', crumb.output())
     else:
         posts_result = post_model().get_all({'user_id':user.id}, limit = limit, order = 'time DESC')
         if len(posts_result) > 0:
             posts = []
             for post_result in posts_result:
                 post = {'post':post_result}
                 node = node_model().get_one({'id':post_result.node_id})
                 post['node'] = node
                 comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
                 if comment:
                     comment_user = user_model().get_one({'id':comment.user_id})
                     post['comment_user'] = comment_user
                 else:
                     post['comment_user'] = None
                 posts.append(post)
         else:
             posts = None
         comments_result = comment_model().get_all({'user_id':user.id}, limit = limit, order = 'time DESC')
         if len(comments_result) > 0:
             comments = []
             for comment_result in comments_result:
                 post = post_model().get_one({'id':comment_result.post_id})
                 post_user = user_model().get_one({'id':post.user_id})
                 comment = {'post':post, 'comment':comment_result, 'post_user':post_user}
                 comments.append(comment)
         else:
             comments = None
         following = False
         if session.user_id:
             if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'follow', 'meta_value':user.id}):
                 following = True
         return render.profile(user.name, user, posts, comments, following)
Esempio n. 41
0
 def POST(self):
     if not self.form.validates():
         return render.login(self.form, '登录失败,请重登', self.crumb.output())
     condition = {'name' : self.form.d.name}
     # MD5加密 密码
     #condition['password'] = hashlib.md5(condition['password']).hexdigest()
     user = user_model().get_one(condition)
     if user is None:
         return render.login(self.form, '用户名不存在', self.crumb.output())
     auth_from_form = hashlib.md5(hashlib.md5(self.form.d.password).hexdigest() + user.auth).hexdigest()
     if auth_from_form != user.password:
         return render.login(self.form, '密码错误', self.crumb.output())
     user_model().update_session(user.id)
     user_model().set_cookie(user.id)
     data = web.input();
     try:
         if data['next'] is not None:
             raise web.SeeOther(data['next'])
         else:
             raise web.SeeOther('/')
     except KeyError:
         raise web.SeeOther('/')
Esempio n. 42
0
 def GET(self, id):
     limit = 10
     post_model().add_view(id)
     post = post_model().get_one({'id':id})
     if post is None:
         self.crumb.append('主题未找到')
         return render.post_nf('主题未找到', self.crumb.output())
     else:
         post_fav = False
         if session.user_id:
             if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post.id}):
                 post_fav = True
         favs = user_meta_model().count_meta({'meta_key':'post_fav','meta_value':id})
         node = node_model().get_one({'id':post.node_id})
         user = user_model().get_one({'id':post.user_id})
         #return user.name
         self.crumb.append(node.display_name, '/node/'+node.name)
         thanks = False
         if session.user_id is not None:
             if post_thanks_model().get_one({'user_id':session.user_id, 'post_id':post.id}):
                 thanks = True
         condition = {'post_id' : post.id}
         # Pagination
         total = comment_model().count_table(condition)
         pagination = Pagination('/post/'+str(post.id), total, limit = 100)
         page = pagination.true_page(web.input(p=(total/100)*100 + 1)['p'])
         comments_result = comment_model().get_all(condition, order = 'time ASC', limit = 100, offset = (page-1)*100)
         comments = []
         if comments_result is not None:
             for comment_result in comments_result:
                 comment_user = user_model().get_one({'id':comment_result.user_id})
                 comment_thanks = False
                 if session.user_id is not None:
                     if comment_thanks_model().get_one({'user_id':session.user_id, 'comment_id':comment_result.id}):
                         comment_thanks = True
                 comments.append({'comment':comment_result, 'user':comment_user, 'thanks':comment_thanks})
         form = comment_model().form
         return render.post_view(post, user, comments, form, post_fav, favs, thanks, self.crumb.output(), pagination)
Esempio n. 43
0
 def GET(self, id):
     limit = 10
     post_model().add_view(id)
     post = post_model().get_one({'id':id})
     if post is None:
         self.crumb.append('主题未找到')
         return render.post_nf('主题未找到', self.crumb.output())
     else:
         post_fav = False
         if session.user_id:
             if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'post_fav', 'meta_value':post.id}):
                 post_fav = True
         favs = user_meta_model().count_meta({'meta_key':'post_fav','meta_value':id})
         node = node_model().get_one({'id':post.node_id})
         user = user_model().get_one({'id':post.user_id})
         #return user.name
         self.crumb.append(node.display_name, '/node/'+node.name)
         thanks = False
         if session.user_id is not None:
             if post_thanks_model().get_one({'user_id':session.user_id, 'post_id':post.id}):
                 thanks = True
         condition = {'post_id' : post.id}
         # Pagination
         total = comment_model().count_table(condition)
         pagination = Pagination('/post/'+str(post.id), total, limit = 100)
         page = pagination.true_page(web.input(p=1)['p'])
         comments_result = comment_model().get_all(condition, order = 'time ASC', limit = 100, offset = (page-1)*100)
         comments = []
         if comments_result is not None:
             for comment_result in comments_result:
                 comment_user = user_model().get_one({'id':comment_result.user_id})
                 comment_thanks = False
                 if session.user_id is not None:
                     if comment_thanks_model().get_one({'user_id':session.user_id, 'comment_id':comment_result.id}):
                         comment_thanks = True
                 comments.append({'comment':comment_result, 'user':comment_user, 'thanks':comment_thanks})
         form = comment_model().form
         return render.post_view(post, user, comments, form, post_fav, favs, thanks, self.crumb.output(), pagination)
Esempio n. 44
0
 def POST(self, node_name):
     if session.user_id is None:
         raise web.SeeOther('/login?next=/post/create' + node_name)
     conditions = {'name' : node_name}
     node = node_model().get_one(conditions)
     if node is None:
         return render.not_found('节点未找到', '节点未找到')
     if not self.form.validates():
         return render.create_post(self.form, '创建失败, 请重创:D', self.crumb.output())
     user_model().update_session(session.user_id)
     length, cost = money_model().cal_post(self.form.d.content)
     if session.money < cost:
         self.crumb.append('财富不够')
         return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
     title = html2db(self.form.d.title)
     content = html2db(self.form.d.content)
     create_time = time.time()
     post_id = post_model().insert({'title' : title, 'content' : content, 'node_id' : node.id, 'time' : create_time, 'last_update':create_time, 'user_id' : session.user_id})
     money_type_id = money_type_model().get_one({'name':'post'})['id']
     money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':post_id})
     
     user_model().update_session(session.user_id)
     raise web.seeother('/post/' + str(post_id))
Esempio n. 45
0
 def GET(self, name):
     limit = 10
     user = user_model().get_one({'name':name})
     crumb = Crumb()
     if user:
         crumb.append(name, '/profile/'+name)
         crumb.append('全部回复')
         total = comment_model().count_table({'user_id':user.id})
         pagination = Pagination('/profile/'+name+'/comments', total, limit = limit)
         page = pagination.true_page(web.input(p=1)['p'])
         comments_result = comment_model().get_all({'user_id':user.id}, limit = limit, offset = (page-1)*limit, order = 'time DESC')
         if len(comments_result) > 0:
             comments = []
             for comment_result in comments_result:
                 post = post_model().get_one({'id':comment_result.post_id})
                 post_user = user_model().get_one({'id':post.user_id})
                 comment = {'post':post, 'comment':comment_result, 'post_user':post_user}
                 comments.append(comment)
         else:
             comments = None
         return render.user_comments('全部回复', comments, total, crumb.output(), pagination.output())
     else:
         crumb.append('会员未找到')
         return render.user_nf('会员未找到', crumb.output())
Esempio n. 46
0
 def POST(self):
     if not self.form.validates():
         return render.login(self.form, '登录失败,请重登', self.crumb.output())
     condition = {'name': self.form.d.name}
     # MD5加密 密码
     #condition['password'] = hashlib.md5(condition['password']).hexdigest()
     user = user_model().get_one(condition)
     if user is None:
         return render.login(self.form, '用户名不存在', self.crumb.output())
     auth_from_form = hashlib.md5(
         hashlib.md5(self.form.d.password).hexdigest() +
         user.auth).hexdigest()
     if auth_from_form != user.password:
         return render.login(self.form, '密码错误', self.crumb.output())
     user_model().update_session(user.id)
     user_model().set_cookie(user.id)
     data = web.input()
     try:
         if data['next'] is not None:
             raise web.SeeOther(data['next'])
         else:
             raise web.SeeOther('/')
     except KeyError:
         raise web.SeeOther('/')
Esempio n. 47
0
 def insert_notify(self, user_id, user_list, notify_type, foreign_id):
     if isinstance(user_list, list):
         for receiver in user_list:
             user = user_model().get_one({"name": receiver})
             if user is not None:
                 self.insert(
                     {
                         "user_id": user_id,
                         "receiver": user.id,
                         "type_id": self.types[notify_type],
                         "foreign_id": foreign_id,
                     }
                 )
     else:
         user = user_model().get_one({"name": user_list})
         if user is not None:
             self.insert(
                 {
                     "user_id": user_id,
                     "receiver": user.id,
                     "type_id": self.types[notify_type],
                     "foreign_id": foreign_id,
                 }
             )
Esempio n. 48
0
 def run(self):
     ltime = time.localtime(time.time())
     time_start = int(
         time.mktime(
             datetime.datetime(ltime.tm_year, ltime.tm_mon,
                               ltime.tm_mday).timetuple()))
     time_end = time_start + 24 * 60 * 60
     sql = 'SELECT `post_id` FROM comment WHERE `time` >= ' + str(
         time_start) + ' AND `time` <= ' + str(
             time_end
         ) + ' GROUP BY post_id ORDER BY count(post_id) DESC LIMIT 10'
     post_ids = comment_model().query_result(sql)
     posts = []
     for row in post_ids:
         post = post_model().get_one({'id': row.post_id})
         user = user_model().get_one({'id': post.user_id})
         posts.append({'post': post, 'user': user})
     return render.hot_posts_tody(posts)
Esempio n. 49
0
 def __init__(self):
     self.form = user_model().signup_form
     self.crumb = Crumb()
     self.crumb.append('注册')