def post(self): args = self.parser.parse_args() if not current_user.is_authenticated: return JSON_abort(401, message="You should login first.") if not check_title(args["title"]): return JSON_abort(400, message="Forbidden symbols") editors = "" if args["editors"]: for nickname in args["editors"].split(", "): user = session.query(User).filter( User.nickname == nickname).first() if not user: return JSON_abort( 400, message=f"Nickname {nickname} not exist.") editors += str(user.id) + "," forum = Forum() forum.title = args["title"] forum.private = args["private"] forum.editors = editors forum.admin_id = current_user.id session.add(forum) session.commit() current_user.follow += str( session.query(Forum).order_by(Forum.id.desc()).first().id) + "," session.commit() return jsonify({'success': 'OK'})
def post(self): args = self.parser.parse_args() user = session.query(User).filter(User.email == args['email']).first() if user and user.check_password(args['password']): login_user(user) return jsonify({'success': 'OK'}) else: JSON_abort(404, message="Wrong email or password")
def post(self): if not current_user.is_authenticated: return JSON_abort(401, message="You should login first.") server = self.parser.parse_args()["server"].strip() if session.query(Bots).filter(Bots.server == server).first(): return JSON_abort(400, message="This server is already in use") bot = session.query(Bots).filter( Bots.user_id == current_user.id).first() if bot: bot.server = server else: bot = Bots() bot.user_id = current_user.id bot.server = server session.add(bot) session.commit() return jsonify({"success": "OK"})
def get(self, forum_id): if not forum_id.isdigit(): return JSON_abort(404, message="Forum not found") forum_id = int(forum_id) forum = session.query(Forum).filter(Forum.id == forum_id).first() if not forum: return JSON_abort(404, message="Forum not found") res = {} if forum.private: if current_user.is_authenticated: if (not current_user.id == forum.admin_id) and (not str( current_user.id) in forum.editors.split(',')): return JSON_abort(403, message="Forbidden") else: return JSON_abort(401, message="You should login first.") res["title"] = forum.title res["private"] = forum.private res["personal"] = forum.personal res["admin_id"] = forum.admin_id res["editors"] = forum.editors.split(',')[:-1] return jsonify({"forum": res})
def get(self, user_id): if not user_id.isdigit(): return JSON_abort(404, message="User not found") user_id = int(user_id) user = session.query(User).filter(User.id == user_id).first() if user: res = {} forums = session.query( Forum.id).filter((Forum.id.in_(user.follow.split(","))) & (~Forum.private)).all() private = session.query( Forum.id).filter((Forum.id.in_(user.follow.split(","))) & (Forum.private)).all() if current_user.is_authenticated: if current_user.id == user_id: res["private_forums"] = private res["email"] = user.email res["personal_forum"] = user.forum_id res["followed"] = forums res["nickname"] = user.nickname return jsonify({"user": res}) return JSON_abort(404, message="User not found")
def get(self, forum_id): if not forum_id.isdigit(): return JSON_abort(404, message="Forum not found") forum_id = int(forum_id) if not current_user.is_authenticated: return JSON_abort(401, message="You should login first.") forum = session.query(Forum).get(forum_id) if not forum: return JSON_abort(404, message="Forum not found") if forum.private and ( (not current_user.id == forum.admin_id) and (not str(current_user.id) in forum.editors.split(','))): return JSON_abort(403, message="Forbidden") messages = session.query(Message).filter( Message.forum_id == forum_id).all() return jsonify({ "messages": [{ "user_id": e.user_id, "message": e.message, "datetime": e.datetime } for e in messages] })
def post(self, forum_id): if not forum_id.isdigit(): return JSON_abort(404, message="Forum not found") forum_id = int(forum_id) if not current_user.is_authenticated: return JSON_abort(401, message="You should login first.") forum = session.query(Forum).get(forum_id) if not forum: return JSON_abort(404, message="Forum not found") if forum.private and ( (not current_user.id == forum.admin_id) and (not str(current_user.id) in forum.editors.split(','))): return JSON_abort(403, message="Forbidden") args = self.parser.parse_args() if not args["message"].strip(): return JSON_abort(400, message="Message is empty") json = {} json['user_id'] = current_user.id json['forum_id'] = forum_id json['message'] = args["message"].strip() json['datetime'] = datetime.now() json['user_nickname'] = current_user.nickname handle_new_message(json) return jsonify({'success': 'OK'})
def get(self): if not current_user.is_authenticated: return JSON_abort(401, message="You should login first.") follow = [ e.id for e in session.query( Forum).filter((Forum.id.in_(current_user.follow.split(","))) & (~Forum.private)).all() ] events = session.query(Event).filter(Event.forum_id.in_(follow)).all() res = {} res['events'] = [] for event in events: if event: res['events'].append({ "id": event.id, "forum_id": event.forum_id, "title": event.title, "description": event.desc, "address": event.geo_point, "date": event.datetime }) return jsonify(res)