Esempio n. 1
0
def handle_login_POST():
    """
    Carries out an actual log in.
    :return:
    """

    # If this is a POST it is a login request.
    #
    username = request.values.get("username")
    password = request.values.get("password")

    # We may or may not have a 'next' field. If we do, we make sure that the URL is safe.
    try:
        session_id = weblab_api.api.login(username, password)
    except InvalidCredentialsError:
        flash(gettext("Invalid username or password"), category="error")
        # _scheme is a workaround. See comment in other redirect.
        return redirect(url_for(".login", _external=True, _scheme=request.scheme))
    except:
        traceback.print_exc()
        flash(gettext("There was an unexpected error while logging in."), 500)
        return weblab_api.make_response(gettext("There was an unexpected error while logging in."), 500)
    else:
        # TODO: Find proper way to do this.
        # This currently redirects to HTTP even if being called from HTTPS. Tried _external as a workaround but didn't work.
        # More info: https://github.com/mitsuhiko/flask/issues/773
        # For now we force the scheme from the request.
        return weblab_api.make_response(redirect(get_next_url()))
Esempio n. 2
0
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except WebError as e:
         return weblab_api.make_response(gettext(e.args[0]), 500)
     except Exception:
         if current_app.debug:
             raise
         traceback.print_exc()
         return weblab_api.make_response(gettext("Error processing request"), 500)
Esempio n. 3
0
 def wrapped(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except WebError as e:
         return weblab_api.make_response(gettext(e.args[0]), 500)
     except Exception:
         if current_app.debug:
             raise
         traceback.print_exc()
         return weblab_api.make_response(
             gettext("Error processing request"), 500)
Esempio n. 4
0
def labs():
    """
    Renders the Laboratories List.
    """
    try:
        weblab_api.api.check_user_session()
    except SessionNotFoundError:
        return redirect(url_for('.login'))

    return weblab_api.make_response(render_template("webclient/labs.html"))
Esempio n. 5
0
def labs():
    """
    Renders the Laboratories List.
    """
    try:
        weblab_api.api.check_user_session()
    except SessionNotFoundError:
        return redirect(url_for('.login'))

    return weblab_api.make_response(render_template("webclient/labs.html"))
Esempio n. 6
0
def demo():
    if not weblab_api.config.client.get('demo.available'):
        return "Not found", 404

    username = weblab_api.config.client.get('demo.username')
    password = weblab_api.config.client.get('demo.password')

    if username is None or password is None:
        # TODO: mail the admin, use an errors template
        return "Invalid configuration! Contact the administrator so he puts the username and password for the demo account"

    try:
        session_id = weblab_api.api.login(username, password)
    except InvalidCredentialsError:
        # TODO: mail the admin, use an errors template
        return "Invalid configuration! Contact the administrator so he correctly puts the username and password for the demo account"
    
    if hasattr(g, 'next_url') or request.args.get('next'):
        return weblab_api.make_response(redirect(get_next_url()))

    return labs_view()