def _auth_check(oauth, meta, verifier, builder, lets_connect):
    """quickly see if the can fetch messages, otherwise reauth"""
    try:
        info = user_info(oauth, meta.api_base_uri)
        _cert_check(meta, oauth, builder, info)
    except EduvpnAuthException:
        GLib.idle_add(lambda: reauth(meta=meta,
                                     verifier=verifier,
                                     builder=builder,
                                     lets_connect=lets_connect))
    except Exception as e:
        error = e
        window = builder.get_object('eduvpn-window')
        GLib.idle_add(lambda: error_helper(
            window, "Can't check account status", "{}".format(str(error))))
        raise
Exemple #2
0
def _background(meta, builder, verifier, lets_connect):
    # type: (Metadata, Gtk.builder, str, bool) -> None
    label = builder.get_object('messages-label')
    window = builder.get_object('eduvpn-window')
    try:
        oauth = oauth_from_token(meta=meta, lets_connect=lets_connect)
    except Exception as e:
        error = e
        GLib.idle_add(lambda: error_helper(
            window, "Can't reconstruct OAuth2 session", (str(error))))
        print(meta)
        raise

    text = ""

    try:
        messages_user = list(user_messages(oauth, meta.api_base_uri))
        messages_system = list(system_messages(oauth, meta.api_base_uri))
        info = user_info(oauth, meta.api_base_uri)
    except EduvpnAuthException:
        GLib.idle_add(lambda: reauth(meta=meta,
                                     verifier=verifier,
                                     builder=builder,
                                     lets_connect=lets_connect))
    except Exception as e:
        error = e
        GLib.idle_add(lambda: error_helper(window, "Can't fetch user messages",
                                           str(error)))
        raise
    else:
        if info['is_disabled']:
            GLib.idle_add(lambda: error_helper(
                window, "This account has been disabled", ""))
        for date_time, type_, message in messages_user:
            logger.info("user message at {}: {}".format(date_time, message))
            text += "<b><big>{}</big></b>\n".format(date_time)
            text += "<small><i>user, {}</i></small>\n".format(type_)
            text += "{}\n\n".format(message)
        for date_time, type_, message in messages_system:
            logger.info("system message at {}: {}".format(date_time, message))
            text += "<b><big>{}</big></b>\n".format(date_time)
            text += "<small><i>system, {}</i></small>\n".format(type_)
            text += "{}\n\n".format(message)
        GLib.idle_add(lambda: label.set_markup(text))
 def test_reauth(self, _):
     reauth(builder=self.builder,
            meta=self.meta,
            verifier=self.verifier,
            lets_connect=False)
 def test_reauth(self, _):
     reauth(builder=self.builder, meta=self.meta, verifier=self.verifier)