Esempio n. 1
0
File: users.py Progetto: xaoei/zulip
def avatar(request: HttpRequest,
           user_profile: UserProfile,
           email_or_id: str,
           medium: bool = False) -> HttpResponse:
    """Accepts an email address or user ID and returns the avatar"""
    is_email = False
    try:
        int(email_or_id)
    except ValueError:
        is_email = True

    try:
        realm = user_profile.realm
        if is_email:
            avatar_user_profile = get_user_including_cross_realm(
                email_or_id, realm)
        else:
            avatar_user_profile = get_user_by_id_in_realm_including_cross_realm(
                int(email_or_id), realm)
        # If there is a valid user account passed in, use its avatar
        url = avatar_url(avatar_user_profile, medium=medium)
    except UserProfile.DoesNotExist:
        # If there is no such user, treat it as a new gravatar
        email = email_or_id
        avatar_version = 1
        url = get_gravatar_url(email, avatar_version, medium)

    # We can rely on the url already having query parameters. Because
    # our templates depend on being able to use the ampersand to
    # add query parameters to our url, get_avatar_url does '?x=x'
    # hacks to prevent us from having to jump through decode/encode hoops.
    assert url is not None
    url = add_query_arg_to_redirect_url(url, request.META['QUERY_STRING'])
    return redirect(url)
Esempio n. 2
0
def get_icon_backend(request: HttpRequest,
                     user_profile: UserProfile) -> HttpResponse:
    url = realm_icon_url(user_profile.realm)

    # We can rely on the URL already having query parameters. Because
    # our templates depend on being able to use the ampersand to
    # add query parameters to our url, get_icon_url does '?version=version_number'
    # hacks to prevent us from having to jump through decode/encode hoops.
    url = add_query_arg_to_redirect_url(url, request.META['QUERY_STRING'])
    return redirect(url)
Esempio n. 3
0
def join_bigbluebutton(
        request: HttpRequest,
        meeting_id: str = REQ(),
        password: str = REQ(),
        checksum: str = REQ(),
) -> HttpResponse:
    assert request.user.is_authenticated

    if settings.BIG_BLUE_BUTTON_URL is None or settings.BIG_BLUE_BUTTON_SECRET is None:
        raise JsonableError(_("BigBlueButton is not configured."))
    else:
        try:
            response = VideoCallSession().get(
                add_query_to_redirect_url(
                    settings.BIG_BLUE_BUTTON_URL + "api/create",
                    urlencode({
                        "meetingID": meeting_id,
                        "moderatorPW": password,
                        "attendeePW": password + "a",
                        "checksum": checksum,
                    }),
                ))
            response.raise_for_status()
        except requests.RequestException:
            raise JsonableError(
                _("Error connecting to the BigBlueButton server."))

        payload = ElementTree.fromstring(response.text)
        if payload.find("messageKey").text == "checksumError":
            raise JsonableError(
                _("Error authenticating to the BigBlueButton server."))

        if payload.find("returncode").text != "SUCCESS":
            raise JsonableError(
                _("BigBlueButton server returned an unexpected error."))

        join_params = urlencode(  # type: ignore[type-var] # https://github.com/python/typeshed/issues/4234
            {
                "meetingID": meeting_id,
                "password": password,
                "fullName": request.user.full_name,
            },
            quote_via=quote,
        )

        checksum = hashlib.sha1(
            ("join" + join_params +
             settings.BIG_BLUE_BUTTON_SECRET).encode()).hexdigest()
        redirect_url_base = add_query_to_redirect_url(
            settings.BIG_BLUE_BUTTON_URL + "api/join", join_params)
        return redirect(
            add_query_arg_to_redirect_url(redirect_url_base,
                                          "checksum=" + checksum))
Esempio n. 4
0
def get_logo_backend(
    request: HttpRequest,
    user_profile: UserProfile,
    night: bool = REQ(json_validator=check_bool)
) -> HttpResponse:
    url = get_realm_logo_url(user_profile.realm, night)

    # We can rely on the URL already having query parameters. Because
    # our templates depend on being able to use the ampersand to
    # add query parameters to our url, get_logo_url does '?version=version_number'
    # hacks to prevent us from having to jump through decode/encode hoops.
    url = add_query_arg_to_redirect_url(url, request.META["QUERY_STRING"])
    return redirect(url)