def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['weibo',]) user = self.current_user profile = Profile.get_by_user(user) profile.weibo = post_data['weibo'] profile.save() self.write(json_result(0, {'user': user.username}))
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['post', 'title', 'content', 'topic']) try: post = Post.get(Post.id == post_data['post'], Post.is_delete == False) except Post.DoesNotExist: self.write(json_result(1, '请选择正确主题')) return if not post.check_auth(self.current_user): self.redirect404_json() return try: topic = PostTopic.get(PostTopic.str == post_data['topic']) except PostTopic.DoesNotExist: self.write(json_result(1, '请选择正确主题')) return post.topic = topic post.title = post_data['title'] post.content = post_data['content'] post.save() # 添加通知, 通知给其他关注的用户 Notification.new_post(post) self.write(json_result(0, {'post_id': post.id}))
def wrapper(self, *args, **kwargs): captcha_cookie = self.get_cookie('captcha', '') captcha = get_cleaned_post_data(self, ['captcha'], blank=True)['captcha'] if not captcha or captcha != captcha_cookie: self.write(json_result(errorcode, result)) return return method(self, *args, **kwargs)
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['username', 'password']) user = User.auth(post_data['username'], post_data['password']) if user: self.set_secure_cookie('uuid', user.username) result = json_result(0, 'login success!') else: result = json_result(-1, 'login failed!') self.write(result)
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, [ 'weibo', ]) user = self.current_user profile = Profile.get_by_user(user) profile.weibo = post_data['weibo'] profile.save() self.write(json_result(0, {'user': user.username}))
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['username', 'password']) user = User.auth(post_data['username'], post_data['password']) if user: # self.set_secure_cookie('uuid', user.username) self.set_current_user(user.username) result = json_result(0, 'login success!') else: result = json_result(-1, MSG.str('login_password_error')) self.write(result)
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['username', 'password']) user = User.auth(post_data['username'], post_data['password']) if user: self.set_secure_cookie('uuid', user.username) self.set_secure_cookie('isteacher', str(user.level)) # print('set user level'+str(user.level)+ str(type(user.level)) ) result = json_result(0, 'login success!') else: result = json_result(-1, '用户名密码错误...') self.write(result)
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['username', 'email', 'password']) if User.get_by_username(username=post_data['username']): self.write(json_result(1, MSG.str('register_same_name'))) return if User.get_by_email(email=post_data['email']): self.write(json_result(1, MSG.str('register_same_email'))) return user = User.new(username=post_data['username'], email=post_data['email'], password=post_data['password']) self.write(json_result(0,{'username': user.username}))
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['title', 'content', 'topic']) try: topic = PostTopic.get(PostTopic.str == post_data['topic']) except PostTopic.DoesNotExist: self.write(json_result(1, '请选择正确主题')) return post = Post.create(topic=topic, title=post_data['title'], content=post_data['content'], user=self.current_user) #添加通知, 通知给其他关注的用户 Notification.new_post(post) self.write(json_result(0, {'post_id': post.id}))
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['username', 'email', 'password']) if User.get_by_username(username=post_data['username']): self.write(json_result(1, '用户名经存在')) return if User.get_by_email(email=post_data['email']): self.write(json_result(1, '邮箱已经存在')) return user = User.new(username=post_data['username'], email=post_data['email'], password=post_data['password']) self.write(json_result(0, {'username': user.username}))
def post(self, *args, **kwargs): post_data = get_cleaned_post_data(self, ['post', 'content']) try: post = Post.get(Post.id == post_data['post'], Post.is_delete == False) except PostTopic.DoesNotExist: self.write(json_result(1, '请选择正确post')) return postreply = PostReply.create( post=post, user=self.current_user, content=post_data['content'], ) post.update_latest_reply(postreply) Notification.new_reply(postreply, post) self.write(json_result(0, {'post_id': post.id}))