Ejemplo n.º 1
0
def lab(category_name, experiment_name):
    """
    Renders a specific laboratory.
    """
    try:
        experiment_list = weblab_api.api.list_experiments(experiment_name, category_name)

        experiment = None
        for exp_allowed in experiment_list:
            if exp_allowed.experiment.name == experiment_name and exp_allowed.experiment.category.name == category_name:
                experiment = _get_experiment(exp_allowed)

        if experiment is None:
            # TODO: check what to do in case there is no session_id (e.g., federated mode)
            if weblab_api.db.check_experiment_exists(experiment_name, category_name):
                flash(gettext("You don't have permission on this laboratory"), 'danger')
            else:
                flash(gettext("Experiment does not exist"), 'danger')
            return redirect(url_for('.labs'))

        # Get the target URL for the JS API.
        lab_url = url_for(".static", filename="")

        return render_template("webclient/lab.html", experiment=experiment, lab_url=lab_url)
    except Exception as ex:
        raise
Ejemplo n.º 2
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()))
Ejemplo n.º 3
0
def to_human(seconds):
    if seconds < 60:
        return gettext("%(num)s sec", num="%.2f" % seconds)
    elif seconds < 3600:
        return gettext("%(min)s min %(sec)s sec", min=(int(seconds) / 60), sec=(int(seconds) % 60))
    elif seconds < 24 * 3600:
        return gettext("%(hours)s hour %(min)s min", hours=(int(seconds) / 3600), min=(int(seconds) % 3600 / 60))
    else:
        return gettext("%(days)s days", days = (int(seconds) / (3600 * 24)))
Ejemplo n.º 4
0
def login_json():
    contents = request.get_json(force=True, silent=True)
    if contents == False or not isinstance(contents, dict):
        return weblab_api.jsonify(error = True, message = "Error reading username and password")

    username = contents.get('username', '')
    password = contents.get('password', '')

    try:
        session_id = weblab_api.api.login(username, password)
    except InvalidCredentialsError:
        return weblab_api.jsonify(error = True, message = gettext("Invalid username or password"))

    return weblab_api.jsonify(error = False, redirect = get_next_url())
Ejemplo n.º 5
0
def gefx(session, condition):
    links, _ = generate_links(session, condition)
    if not links:
        return gettext("This groups does not have any detected plagiarism")

    G = nx.DiGraph()
    
    for source_node in links:
        for target_node in set(links[source_node]):
            weight = links[source_node].count(target_node)
            G.add_edge(source_node, target_node, weight=weight)

    out_degrees = G.out_degree()
    in_degrees = G.in_degree()

    for name in G.nodes():
         G.node[name]['out_degree'] = out_degrees[name]
         G.node[name]['in_degree'] = in_degrees[name]

    G_undirected = G.to_undirected();
    partitions = best_partition(G_undirected)
    colors = {}
    for member, c in partitions.items():
        if not colors.has_key(c):
            r = random.randrange(64,192)
            g = random.randrange(64,192)
            b = random.randrange(64,192)
            colors[c] = (r, g, b)
        G.node[member]["viz"] = {
            'color': { 
              'r': colors[c][0],
              'g': colors[c][1],
              'b': colors[c][2],
            },
            'size': 5 * G.node[member]['out_degree']
        }

    output = StringIO()
    nx.write_gexf(G, output)
    return Response(output.getvalue(), mimetype='text/xml')
Ejemplo n.º 6
0
    def index(self):
        login = get_app_instance(self).get_user_information().login
        user = self._session.query(model.DbUser).filter_by(login = login).one()
        
        facebook_id = ''

        change_password = True
        password_auth = None
        facebook_auth = None

        for user_auth in user.auths:
            if user_auth.auth.auth_type.name.lower() == 'facebook':
                facebook_id = user_auth.configuration
                facebook_auth = user_auth
            if 'ldap' in user_auth.auth.auth_type.name.lower():
                change_password = False
            if user_auth.auth.auth_type.name.lower() == 'db':
                password_auth = user_auth


        if len(request.form):
            form = ProfileEditForm(request.form)
        else:
            form = ProfileEditForm()
            form.full_name.data = user.full_name
            form.login.data     = user.login
            form.email.data     = user.email
            form.facebook.data  = facebook_id

        user_permissions = get_app_instance(self).get_permissions()
        
        change_profile = True
        for permission in user_permissions:
            if permission.name == permissions.CANT_CHANGE_PROFILE:
                change_password = False
                change_profile  = False

        if change_profile and form.validate_on_submit():

            errors = []

            if change_password and password_auth is not None and form.password.data:
                if len(form.password.data) < 6:
                    errors.append(gettext("Error: too short password"))
                else:
                    password_auth.configuration = password2sha(form.password.data)

            user.email = form.email.data
            
            if form.facebook.data:
                if facebook_auth is None:
                    auth = self._session.query(model.DbAuth).filter_by(name = 'FACEBOOK').one()
                    new_auth = model.DbUserAuth(user, auth, form.facebook.data)
                    self._session.add(new_auth)
                else:
                    facebook_auth.configuration = form.facebook.data
            else:
                if facebook_auth is not None:
                    self._session.delete(facebook_auth)

            self._session.commit()

            if errors:
                for error in errors:
                    flash(error)
            else:
                flash(gettext("Saved"))

        return self.render("profile/profile-edit.html", form=form, change_password=change_password, change_profile=change_profile)