예제 #1
0
def login():
    # retrieves the next field that may be used latter
    # to re-direct the user back to the original place
    next = quorum.get_field("next")

    # retrieves the username and the password fields
    # and uses them to run the login logic raising an
    # error in case an invalid authentication occurs
    username = quorum.get_field("username")
    password = quorum.get_field("password")
    try: account = models.Account.login(username, password)
    except quorum.OperationalError as error:
        return flask.render_template(
            "signin.html.tpl",
            username = username,
            next = next,
            error = error.message
        )

    # updates the current user (name) in session with
    # the username that has just be accepted in the login
    flask.session["username"] = account.username
    flask.session["tokens"] = account.tokens

    # makes the current session permanent this will allow
    # the session to persist along multiple browser initialization
    flask.session.permanent = True

    return flask.redirect(
        next or flask.url_for("index")
    )
예제 #2
0
def import_do():
    # retrieves the import file values (reference to the
    # uploaded file) and then validates if it has been
    # defined, in case it fails prints the template with
    # the appropriate error variable set
    import_file = quorum.get_field("import_file", None)
    if import_file == None or not import_file.filename:
        return flask.render_template(
            "settings/import.html.tpl",
            link = "settings",
            sub_link = "import",
            error = "No file defined"
        )

    # creates a temporary file path for the storage of the file
    # and then saves it into that directory
    fd, file_path = tempfile.mkstemp()
    import_file.save(file_path)

    # retrieves the database and creates a new export manager for
    # the currently defined entities then imports the data defined
    # in the current temporary path
    adapter = quorum.get_adapter()
    manager = quorum.export.ExportManager(
        adapter,
        multiple = quorum.resolve()
    )
    try: manager.import_data(file_path)
    finally: os.close(fd); os.remove(file_path)
    return flask.redirect(
        flask.url_for(
            "import_a",
            message = "Database file imported with success"
        )
    )
예제 #3
0
def logout():
    next = quorum.get_field("next")

    if "username" in flask.session: del flask.session["username"]
    if "tokens" in flask.session: del flask.session["tokens"]

    return flask.redirect(
        flask.url_for("signin", next = next)
    )
예제 #4
0
def do_video_event():
    url = quorum.get_field("url")

    pusher = quorum.get_pusher()
    pusher.trigger("global", "video.open", {
        "url" : url
    })

    return flask.redirect(
        flask.url_for("base_events")
    )
예제 #5
0
def video():
    url = quorum.get_field("url")

    pusher = quorum.get_pusher()
    pusher.trigger("global", "video.open", {
        "url" : url
    })

    return flask.redirect(
        flask.url_for("index")
    )
예제 #6
0
def do_basic_config():
    config = models.BasicConfig.singleton()
    try: config.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "config/basic.html.tpl",
            link = "config",
            sub_link = "basic",
            config = error.model,
            errors = error.errors
        )

    # redirects the user to the overall configuration
    # selection, as this is the default behavior
    return flask.redirect(
        flask.url_for("base_config")
    )
예제 #7
0
def create_log():
    # creates the new log, using the provided arguments and
    # then saves it into the data source, all the validations
    # should be ran upon the save operation
    log = models.Log.new()
    try: log.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "log/new.html.tpl",
            link = "logs",
            sub_link = "create",
            log = error.model,
            errors = error.errors
        )

    # redirects the user to the page that displays the list
    # of logs for the current account in session
    return flask.redirect(
        flask.url_for("list_logs")
    )
예제 #8
0
def create_account():
    # creates the new account, using the provided arguments and
    # then saves it into the data source, all the validations
    # should be ran upon the save operation
    account = models.Account.new()
    try: account.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "account/new.html.tpl",
            link = "accounts",
            sub_link = "create",
            account = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the set that
    # was just created (normal workflow)
    return flask.redirect(
        flask.url_for("show_account", username = account.username)
    )
예제 #9
0
def update_account(username):
    # finds the current account and applies the provided
    # arguments and then saves it into the data source,
    # all the validations should be ran upon the save operation
    account = models.Account.get(username = username)
    account.apply()
    try: account.save()
    except quorum.ValidationError as error:
        return flask.render_template(
            "account/edit.html.tpl",
            link = "accounts",
            sub_link = "edit",
            account = error.model,
            errors = error.errors
        )

    # redirects the user to the show page of the account that
    # was just updated
    return flask.redirect(
        flask.url_for("show_account", username = username)
    )
예제 #10
0
def github_oauth():
    code = quorum.get_field("code")
    next = quorum.get_field("state")
    error = quorum.get_field("error")
    error_description = quorum.get_field("error_description")
    if error:
        return flask.render_template(
            "error.html.tpl",
            error = error,
            description = error_description
        )

    api = models.GithubConfig.get_api()
    access_token = api.oauth_access(code)
    user = api.self_user()
    config = models.GithubConfig.singleton()
    config.access_token = access_token
    config.username = user["login"]
    config.save()
    flask.session["gh.access_token"] = access_token
    return flask.redirect(
        next or flask.url_for("index")
    )
예제 #11
0
def reset_do():
    quorum.drop_mongo_db()
    return flask.redirect(
        flask.url_for("settings")
    )
예제 #12
0
def delete_account(username):
    account = models.Account.get(username = username)
    account.delete()
    return flask.redirect(
        flask.url_for("list_accounts")
    )