Example #1
0
def status(request, template_name="latch_status.html"):
    """
    Gives information about Latch status, if it's configured,
    and data relative to the user making the request.
    """
    configured = True
    try:
        LatchSetup.instance()
    except ImproperlyConfigured:
        configured = False

    acc_id = None
    account_status = None
    try:
        if configured:
            acc_id = UserProfile.accountid(request.user)
            if acc_id:
                latch_instance = LatchSetup.instance()
                status_response = latch_instance.status(acc_id)
                data = status_response.get_data()["operations"]
                account_status = data[LatchSetup.appid()]["status"]

    except HTTPException:
        logger.exception("Couldn't connect with Latch service")
        return render(request, template_name, {"error": True})

    return render(
        request,
        template_name,
        {
            "configured": configured,
            "accountid": acc_id,
            "account_status": account_status,
        },
    )
Example #2
0
    def latch_permits_login(user):
        if not LatchSetup.is_configured() or not UserProfile.accountid(user):
            # Always return on if is not configured or the user does not have latch configured
            return True

        try:
            latch_instance = LatchSetup.instance()
            status_response = latch_instance.status(UserProfile.accountid(user))
            data = status_response.get_data()
            return data["operations"][LatchSetup.appid()]["status"] == "on"
        except HTTPException:
            logger.exception("Couldn't connect with Latch service")
            bypass = getattr(settings, "LATCH_BYPASS_WHEN_UNREACHABLE", True)
            if bypass:
                logger.info("Bypassing login attempt")

            return bool(bypass)
Example #3
0
 def test_configured_app_returns_correct_app_id(self):
     self.assertEqual(LatchSetup.appid(), "abcdefghijklmnopqrst")