def post(self): nick = self.get_body_argument('nick', None) password = self.get_body_argument('password', None) password_confirm = self.get_body_argument('password_confirm', None) invite_code = self.get_body_argument('invite_code', None) if nick and password and password_confirm and invite_code: length = len(password) if length >= 6 and length <= 18 and password == password_confirm: if Member.isExist(nick): self.send_result(error_code=constants.error_code['user_has_exist']) return query_invite_code = 'select count(1) count from tb_invite where code = %s' code_num = db.get(query_invite_code, invite_code) if code_num and code_num.count: md5 = hashlib.md5() md5.update(password) password_md5 = md5.hexdigest() now = datetime.datetime.now() insert_sql = 'insert into tb_user (nick, password, created) values (%s, %s, %s)' try: member_id = db.insert(insert_sql, nick, password_md5, now) self.send_result(True, error_code=None) return except: pass # TODO add log elif not code_num.count: self.send_result(error_code=constants.error_code['invite_code_not_exist']) return self.send_result()
def post(self): nick = self.get_body_argument('nick', None) password = self.get_body_argument('password', None) password_confirm = self.get_body_argument('password_confirm', None) invite_code = self.get_body_argument('invite_code', None) if nick and password and password_confirm and invite_code: length = len(password) if length >= 6 and length <= 18 and password == password_confirm: if Member.isExist(nick): self.send_result( error_code=constants.error_code['user_has_exist']) return query_invite_code = 'select count(1) count from tb_invite where code = %s' code_num = db.get(query_invite_code, invite_code) if code_num and code_num.count: md5 = hashlib.md5() md5.update(password) password_md5 = md5.hexdigest() now = datetime.datetime.now() insert_sql = 'insert into tb_user (nick, password, created) values (%s, %s, %s)' try: member_id = db.insert(insert_sql, nick, password_md5, now) self.send_result(True, error_code=None) return except: pass # TODO add log elif not code_num.count: self.send_result(error_code=constants. error_code['invite_code_not_exist']) return self.send_result()
def post(self): title = self.get_body_argument('title', None) #content = self.get_body_argument('content', None) content = self.get_body_argument('html_content', None) category_id = self.get_body_argument('category', None) user_id = self.current_user.id post_public = self.get_body_argument('privacy', None) post_id = self.get_body_argument('id', -1) draft = self.get_body_argument('draft', 0) visible = 1 - int(draft) if title and content and category_id: now = datetime.now() if int(post_id) != -1: sql = 'update tb_post set title = %s, content = %s, public = %s, visible = %s, category_id = %s, updated = %s where id = %s and deleted = 0' num = db.update(sql, title, content, int(post_public), int(visible), int(category_id), now, int(post_id)) else: sql = 'insert into tb_post (title, content, user_id, category_id, public, visible, created) values (%s, %s, %s, %s, %s, %s, %s)' num = db.insert(sql, title, content, long(user_id), int(category_id), int(post_public), int(visible), now) if num: self.send_result(True, error_code=None) return self.send_result() return self.send_result(error_code=constants.error_code['missing_parameters'])
def post(self): post_id = self.get_body_argument('post_id', None) if post_id: has_liked = self.get_cookie('like') if not has_liked: now = datetime.datetime.now() if self.current_user: has_user_liked = 'select count(1) count from tb_interaction where user_id = %s and post_id = %s' liked_count = db.get(has_user_liked, self.current_user.id, int(post_id)) if not liked_count.count: add_like = 'insert into tb_interaction (user_id, post_id, `like`, unlike, created) values (%s, %s, %s, %s, %s)' like_id = db.insert(add_like, self.current_user.id, post_id, 1, 0, now) if like_id: #self.set_cookie('like_post_{0}'.format(post_id), '1', expires_days=999) self.send_result(True, error_code=None) return else: add_like = 'insert into tb_interaction (post_id, `like`, unlike, created) values (%s, %s, %s, %s)' like_id = db.insert(add_like, post_id, 1, 0, now) if like_id: #self.set_cookie('like_post_{0}'.format(post_id), '1', expires_days=999) self.send_result(True, error_code=None)
def post(self): category = self.get_body_argument('cate_name') if category: query_exist = 'select count(*) count from tb_category where name = %s and user_id = %s' num = db.get(query_exist, category, self.current_user.id) if num and num.count: self.write({'success': False, 'error_code': constants.error_code['category_already_exist']}) self.finish() return query_new = 'insert into tb_category (name, user_id, visible) values (%s, %s, %s)' id = db.insert(query_new, category, self.current_user.id, 1) if id: self.write({'success': True, 'category_id': id}) self.finish()
def get(self): count_code = 'select count(1) count from tb_invite where inviter_id = %s and used = 0' count_obj = db.get(count_code, self.current_user.id) if count_obj.count >= 3: self.send_result(error_code=constants.error_code['invitation_reached_limit']) return code = '' for i in range(8): code += str(random.randint(0, 9)) insert_code = 'insert into tb_invite (inviter_id, code, created, used) values (%s, %s, %s, %s)' id = db.insert(insert_code, self.current_user.id, code, datetime.datetime.now(), 0) if id: self.send_result(True, code, None) return self.send_result()
def get(self): count_code = 'select count(1) count from tb_invite where inviter_id = %s and used = 0' count_obj = db.get(count_code, self.current_user.id) if count_obj.count >= 3: self.send_result( error_code=constants.error_code['invitation_reached_limit']) return code = '' for i in range(8): code += str(random.randint(0, 9)) insert_code = 'insert into tb_invite (inviter_id, code, created, used) values (%s, %s, %s, %s)' id = db.insert(insert_code, self.current_user.id, code, datetime.datetime.now(), 0) if id: self.send_result(True, code, None) return self.send_result()
def post(self): category = self.get_body_argument('cate_name') if category: query_exist = 'select count(*) count from tb_category where name = %s and user_id = %s' num = db.get(query_exist, category, self.current_user.id) if num and num.count: self.write({ 'success': False, 'error_code': constants.error_code['category_already_exist'] }) self.finish() return query_new = 'insert into tb_category (name, user_id, visible) values (%s, %s, %s)' id = db.insert(query_new, category, self.current_user.id, 1) if id: self.write({'success': True, 'category_id': id}) self.finish()