Example #1
0
def _background(meta, oauth, builder, config_dict, lets_connect):
    # type: (Metadata, str, Gtk.builder, dict, bool) -> None
    window = builder.get_object('eduvpn-window')

    try:
        info = user_info(oauth, meta.api_base_uri)
        meta.user_id = info['user_id']
    except Exception as e:
        error = e
        GLib.idle_add(lambda: error_helper(window, "Can't fetch user info", str(error)))
        raise

    if info['is_disabled']:
        GLib.idle_add(lambda: error_helper(window, "This account has been disabled", ""))

    if info['two_factor_enrolled']:
        # Multiple 2fa can be enrolled, but we only support one.
        meta.username = info['two_factor_enrolled_with'][0]
        GLib.idle_add(lambda: finalizing_step(meta=meta, builder=builder, config_dict=config_dict,
                                              lets_connect=lets_connect))
    else:
        if len(meta.two_factor_method) == 0:
            logger.info("no two factor auth enabled on server")
            GLib.idle_add(lambda: finalizing_step(meta=meta, builder=builder, config_dict=config_dict,
                                                  lets_connect=lets_connect))
        elif len(meta.two_factor_method) > 1:
            logger.info("Multi two factor methods available")
            GLib.idle_add(lambda: _choice_window(options=meta.two_factor_method, meta=meta, oauth=oauth,
                                                 builder=builder, config_dict=config_dict, lets_connect=lets_connect))
        else:
            GLib.idle_add(lambda: _enroll(oauth=oauth, meta=meta, builder=builder, config_dict=config_dict,
                                          lets_connect=lets_connect))
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
Example #3
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 background(meta, oauth, builder):
    window = builder.get_object('eduvpn-window')

    try:
        info = user_info(oauth, meta.api_base_uri)
    except Exception as e:
        GLib.idle_add(
            lambda: error_helper(window, "Can't fetch user info", str(e)))
        raise

    if info['is_disabled']:
        GLib.idle_add(
            lambda: error_helper(window, "This account has been disabled", ""))

    if not info['two_factor_enrolled']:
        logger.info("no two factor auth enabled")
        GLib.idle_add(
            lambda: finalizing_step(oauth=oauth, meta=meta, builder=builder))

    elif 'two_factor_enrolled_with' in info:
        options = info['two_factor_enrolled_with']
        if len(options) > 1:
            GLib.idle_add(lambda: choice_window(
                options=options, meta=meta, oauth=oauth, builder=builder))
            return
        elif len(options) == 1:
            logger.info(
                "selection only one two-factor auth methods available ({})".
                format(options[0]))
            meta.username = options[0]
        else:
            GLib.idle_add(lambda: error_helper(
                window, "two_factor_enrolled_with' doesn't contain any fields",
                ""))
        GLib.idle_add(
            lambda: finalizing_step(oauth=oauth, meta=meta, builder=builder))
Example #5
0
 def test_user_info(self):
     user_info(oauth=self.oauth, api_base_uri='http://test')