def delete(timer_id): query_db("DELETE FROM timers WHERE id = ? AND instance_id = ?", [timer_id, session["instance_id"]], commit=True) flash("Timer deleted successfully") return redirect(url_for("timers.index"))
def delete(file_id): file = query_db("SELECT path FROM files WHERE id = ? AND instance_id = ?", [file_id, session["instance_id"]])[0] os.remove(get_upload_path(file["path"])) query_db("DELETE FROM files WHERE id = ? AND instance_id = ?", [file_id, session["instance_id"]], commit=True) flash("File deleted successfully") return redirect(url_for("files.index"))
def add(): timer_name = request.form.get("name") timer_dt = request.form.get("dt") query_db( "INSERT INTO timers (name, dt, instance_id) VALUES (?, ?, ?)", [timer_name, timer_dt, session["instance_id"]], commit=True, ) flash("Timer added successfully") return redirect(url_for("timers.index"))
def edit(timer_id): timer_name = request.form.get("name") timer_dt = request.form.get("dt") query_db( "UPDATE timers SET name = ?, dt = ? WHERE id = ? AND instance_id = ?", [timer_name, timer_dt, timer_id, session["instance_id"]], commit=True, ) flash("Timer updated successfully") return redirect(url_for("timers.index"))
def edit(note_id): note_title = request.form.get("title") note_content = request.form.get("content") note_language = request.form.get("language") query_db( "UPDATE notes SET title = ?, content = ?, language = ? WHERE id = ? AND instance_id = ?", [note_title, note_content, note_language, note_id, session["instance_id"]], commit=True, ) flash("Note updated successfully") return redirect(url_for("notes.index"))
def add(): note_title = request.form.get("title") note_content = request.form.get("content") note_language = request.form.get("language") query_db( "INSERT INTO notes (title, content, language, instance_id) VALUES (?, ?, ?, ?)", [note_title, note_content, note_language, session["instance_id"]], commit=True, ) flash("Note added successfully") return redirect(url_for("notes.index"))
def edit(task_id): task_title = request.form.get("title") task_description = request.form.get("description") task_status = request.form.get("status") query_db( "UPDATE tasks SET title = ?, description = ?, status = ? WHERE id = ? AND instance_id = ?", [task_title, task_description, task_status, task_id, session["instance_id"]], commit=True, ) flash("Task updated successfully") return redirect(url_for("tasks.index"))
def add(): task_title = request.form.get("title") task_description = request.form.get("description") task_status = request.form.get("status") query_db( "INSERT INTO tasks (title, description, status, instance_id) VALUES (?, ?, ?, ?)", [task_title, task_description, task_status, session["instance_id"]], commit=True, ) flash("Task added successfully") return redirect(url_for("tasks.index"))
def download(file_id): f = query_db( "SELECT name, path FROM files WHERE id = ? AND instance_id = ?", [file_id, session["instance_id"]])[0] return send_file(get_upload_path(f["path"]), download_name=f["name"], as_attachment=True)
def login(): if request.method == "POST": instance_name = request.form.get("instance") instance_password = request.form.get("password") instance = query_db( "SELECT id, password FROM instances WHERE name = ?", [instance_name]) if not instance: flash("No instance with given name") else: instance = instance[0] if check_password_hash(instance["password"], instance_password): session["instance_id"] = instance["id"] session["instance_name"] = instance_name else: flash("Wrong password") return redirect(url_for("index")) else: if "instance_id" in session: return redirect(url_for("index")) else: return render_template("auth/login.html")
def index(): notes = query_db("SELECT id, title, content, language FROM notes WHERE instance_id = ?", [session["instance_id"]]) return render_template( "notes.html", notes=notes, )
def init_project(project_name): click.echo(click.style(HEADER, fg="yellow")) click.echo(click.style(f"(!) Initializing project '{project_name}'", fg="yellow")) try: project_desc = input("description: ") project_repo = input("repository: ") project_password = getpass.getpass("password: "******"INSERT INTO instances (name, password, description, repository) VALUES (?, ?, ?, ?)", [project_name, project_password, project_desc, project_repo], commit=True, ) click.echo(click.style("\n(!) Project details saved", fg="blue")) except KeyboardInterrupt: click.echo(click.style("\n(!) Project initialization canceled", fg="red"))
def index(): instance_id = session["instance_id"] instance = query_db( "SELECT description, repository FROM instances WHERE id = ?", [instance_id])[0] return render_template("dashboard.html", instance_desc=instance["description"], instance_repo=instance["repository"])
def upload(): file = request.files["file"] if file and allowed_file(file.filename): filename = secure_filename(file.filename) path = uuid.uuid4().hex query_db( "INSERT INTO files (name, path, instance_id) VALUES (?, ?, ?)", [filename, path, session["instance_id"]], commit=True, ) file.save(get_upload_path(path)) flash("File uploaded successfully") else: flash("Wrong filetype!") return redirect(url_for("files.index"))
def change_password(): if request.method == "POST": old_password = request.form.get("old_password", "") new_password = request.form.get("new_password", "") new_password_confirmation = request.form.get( "new_password_confirmation", "") instance = query_db("SELECT password FROM instances WHERE id = ?", [session["instance_id"]])[0] if not check_password_hash(instance["password"], old_password): flash("Old password is not valid") elif new_password != new_password_confirmation: flash("Password confirmation does not match the new password") elif new_password == old_password: flash("New password cannot be the same as old password") else: query_db("UPDATE instances SET password = ?", [generate_password_hash(new_password)], commit=True) flash("Password changed successfully") return redirect(url_for("index")) return render_template("auth/change_password.html")
def delete(note_id): query_db("DELETE FROM notes WHERE id = ? AND instance_id = ?", [note_id, session["instance_id"]], commit=True) flash("Note deleted successfully") return redirect(url_for("notes.index"))
def index(): files = query_db("SELECT id, name FROM files WHERE instance_id = ?", [session["instance_id"]]) return render_template("files.html", files=files)
def index(): timers = query_db("SELECT id, name, dt FROM timers WHERE instance_id = ?", [session["instance_id"]]) return render_template("timers.html", timers=timers)
def index(): tasks = query_db("SELECT id, title, description, status FROM tasks WHERE instance_id = ?", [session["instance_id"]]) return render_template("tasks.html", tasks=tasks, statuses=TaskStatus.get_choices())