(entry_id: int)
| 1946 | |
| 1947 | @app.route("/vault/edit/<int:entry_id>", methods=["GET", "POST"]) |
| 1948 | def vault_edit(entry_id: int): |
| 1949 | gate = require_vault() |
| 1950 | if gate: |
| 1951 | return gate |
| 1952 | con = db_connect() |
| 1953 | row = con.execute("SELECT * FROM entries WHERE id=?", (entry_id,)).fetchone() |
| 1954 | con.close() |
| 1955 | if not row: |
| 1956 | flash("Entry not found.") |
| 1957 | return redirect(url_for("vault_home")) |
| 1958 | master = vault_master() |
| 1959 | try: |
| 1960 | username = vault_decrypt(master, row["username_enc"]) |
| 1961 | password = vault_decrypt(master, row["password_enc"]) |
| 1962 | notes = vault_decrypt(master, row["notes_enc"]) |
| 1963 | except Exception: |
| 1964 | flash("Could not decrypt entry. Unlock the vault again.") |
| 1965 | return redirect(url_for("vault_logout")) |
| 1966 | if request.method == "POST": |
| 1967 | title = (request.form.get("title") or "").strip() |
| 1968 | url = (request.form.get("url") or "").strip() |
| 1969 | username = request.form.get("username") or "" |
| 1970 | password = request.form.get("password") or "" |
| 1971 | notes = request.form.get("notes") or "" |
| 1972 | if not title or not url: |
| 1973 | flash("Title and URL are required.") |
| 1974 | else: |
| 1975 | con = db_connect() |
| 1976 | con.execute( |
| 1977 | "UPDATE entries SET title=?, url=?, username_enc=?, password_enc=?, notes_enc=?, updated_at=? WHERE id=?", |
| 1978 | (title, url, vault_encrypt(master, username), vault_encrypt(master, password), vault_encrypt(master, notes), int(time.time()), entry_id) |
| 1979 | ) |
| 1980 | con.commit() |
| 1981 | con.close() |
| 1982 | flash("Entry updated.") |
| 1983 | return redirect(url_for("vault_view", entry_id=entry_id)) |
| 1984 | body = render_template_string( |
| 1985 | """ |
| 1986 | <section class="hero stack"> |
| 1987 | <h1 style="margin:0;">Edit entry</h1> |
| 1988 | <form method="post" class="grid2"> |
| 1989 | <div class="card stack"> |
| 1990 | <div><label>Title</label><input name="title" value="{{ r['title'] }}" required></div> |
| 1991 | <div><label>URL</label><input name="url" value="{{ r['url'] }}" required></div> |
| 1992 | <div><label>Username</label><input name="username" value="{{ username }}"></div> |
| 1993 | <div><label>Password</label><input type="password" name="password" value="{{ password }}" id="editPass"></div> |
| 1994 | <div class='row'><button class='btn' type='button' onclick="document.getElementById('editPass').value=Math.random().toString(36).slice(2)+Math.random().toString(36).slice(2)">Generate password</button></div> |
| 1995 | </div> |
| 1996 | <div class="card stack"> |
| 1997 | <div><label>Notes</label><textarea name="notes">{{ notes }}</textarea></div> |
| 1998 | <div class="row"><button class="btn primary" type="submit">Save</button><a class="btn" href="{{ url_for('vault_view', entry_id=r['id']) }}">Cancel</a></div> |
| 1999 | </div> |
| 2000 | </form> |
| 2001 | </section> |
| 2002 | """, r=row, username=username, password=password, notes=notes |
| 2003 | ) |
| 2004 | return render_page("Edit entry", body) |
| 2005 |
nothing calls this directly
no test coverage detected