def room(room_id: str) -> Any: """Room page.""" if routes.gateway(): return render_template("banned.html") if type(room_id) != str: room_id = str(room_id) # Redirect if session is not defined. if "username" not in session: return redirect("/") elif session["username"] == "": return redirect("/") room_role = user_utils.get_account_room_role(session["username"], room_id) # Set jinja values. room_name = room_utils.get_room_name(room_id) is_admin = room_role == "Room Owner" or room_role == "Room Admin" user_id = user_utils.get_account_info(session["username"])[4] return render_template("chat.html", room_id=str(room_id), room_name=room_name, username=session["username"], room_admin=is_admin, user_id=user_id)
def get_members_exclude_user(user, group): members = [] account_info = user_utils.get_account_info(user) for member_key in group.members: if member_key != account_info.key: members.append(member_key.get()) return members
def handle_post(self, user): new_group = Group(parent=user_utils.get_parent_key(user), groupName=self.request.get("name"), groupDescription=self.request.get("description"), members=[user_utils.get_account_info(user).key]) new_group.put() self.redirect("/group?group_key=" + new_group.key.urlsafe())
def connected(data: dict) -> None: """Set status of user when they connect to a room.""" client_socket = create_app.socketio room_id = data["params"] pong = data["pong"] if routes.gateway(): chat_utils.log(f"[{time.asctime()}]<span class=\"server\">SERVER: " + session["username"] + " has been banned."+"</span>", str(room_id)) client_socket.emit("redirect") return elif "anything" not in session: session["anything"] = "" session["login_error"] = "" session["register_error"] = "" session["username"] = "" session["chat"] = "" session["room_id"] = "" client_socket.emit("redirect") return user_utils.status(session["username"], "Joined") seen = user_utils.get_account_info(session["username"])[3] if (datetime.now().minute - user_utils.convert_to_datetime(seen).minute) >= 10: user_utils.online(1, room_id) else: user_utils.online(1, room_id, silent=True) client_socket.emit(pong)
def handle_post(self, user): userInfo = user_utils.get_account_info(user) userInfo.name = self.request.get("inputName") userInfo.nickname = self.request.get("inputNickname") userInfo.email = self.request.get("inputEmail") userInfo.phoneNumber = self.request.get("inputPhoneNumber") userInfo.put() self.redirect("/profile")
def get_groups(user): groups = Group.query().fetch() account_info = user_utils.get_account_info(user) groups_have_user = [] for group in groups: if account_info.key in group.members: groups_have_user.append(group) return groups_have_user
def update_values(self, user, values): cookie = facebook.get_user_from_cookie(self.request.cookies, FACEBOOK_APP_ID, FACEBOOK_APP_SECRET) friend_list = friends_utils.get_friends_list_from_cookie(cookie) values["friends_list"] = friend_list account_info = user_utils.get_account_info(user) for friend in friend_list: if friend.key not in account_info.friendList: account_info.friendList.append(friend.key) account_info.put()
def update_values(self, user, values): userInfo = user_utils.get_account_info(user) event = ndb.Key(urlsafe=self.request.get('event_key')).get() group = ndb.Key(urlsafe=self.request.get('group_key')).get() friends = group_utils.get_members_exclude_user(user, group) expenses = [] for expense in event.expenses: expenses.append(expense.get()) values["event"] = event values["user"] = userInfo values["expenses"] = expenses values["friends_in_event"] = event_utils.get_friends_in_event(friends, event) values["friends_not_in_event"] = event_utils.get_friends_not_in_event(friends, event)
def get(self): template = main.jinja_env.get_template(self.get_template()) user = self.current_user # values = {"account_info": {}, # "facebook_app_id":FACEBOOK_APP_ID} # self.response.out.write(template.render(values)) if user: values = { "current_user": user, "account_info": user_utils.get_account_info(user), "facebook_app_id": FACEBOOK_APP_ID } self.update_values(user, values) self.response.out.write(template.render(values)) else: self.redirect("/")
def handle_post(self, user): userInfo = user_utils.get_account_info(user) event_totalCost = self.request.get("eventTotalCost") if not event_totalCost: event_totalCost = 0 new_event = Event( parent=user_utils.get_parent_key(user), eventName=self.request.get("eventName"), eventDescription=self.request.get("eventDescription"), payer=userInfo.key, totalCost=float(event_totalCost), group_key=self.request.get("group_entity_key")) new_event.put() group_key = ndb.Key(urlsafe=self.request.get("group_entity_key")) group = group_key.get() group.events.append(new_event.key) group.put() self.redirect("/event?event_key=" + new_event.key.urlsafe() + "&group_key=" + group_key.urlsafe())
def create_room(args: dict) -> bool: """Create new room, public or private.""" name = html.escape(args["name"]) desc = html.escape(args["desc"]) public = int(args["public"] == "Public") owner = args["owner"] owner_id = user_utils.get_account_info(owner)[4] new_room_id = base64.b64encode(str( secrets.randbits(128)).encode()).decode() # Append new room info. ret = utils.call_db( event="append table", return_type=bool, data={ "filename": "rooms", "folder": ".", "table": "Rooms", "columns": "Name, Description, ID, Public", "values": f"\"{name}\", \"{desc}\", \"{new_room_id}\", \"{public}\"", "unique": False }) # Create room database. returns = utils.call_db(event="create room", return_type=list, data={ "name": name, "owner": owner, "owner_id": owner_id, "room_id": new_room_id }) return ret and all(r == True for r in returns)
def test_get_account_info(): rss.connect() ret = user_utils.get_account_info("Jush") rss.disconnect() assert type(ret) == list
def get_members(user, group): members = [] account_info = user_utils.get_account_info(user) for member_key in group.members: members.append(member_key.get()) return members
def get_friends_list_from_user(user): account_info = user_utils.get_account_info(user) friends = [] for friend in account_info.friendList: friends.append(friend.get()) return friends