Update public source
This commit is contained in:
@@ -128,6 +128,106 @@ def methods_page():
|
||||
methods=method_rows,
|
||||
)
|
||||
|
||||
@cracklab_bp.route(
|
||||
"/methods/<method_id>/edit/",
|
||||
methods=["GET", "POST"],
|
||||
)
|
||||
def method_edit_page(method_id: str):
|
||||
error = None
|
||||
|
||||
conn = connect_database()
|
||||
|
||||
try:
|
||||
service = MethodService(conn)
|
||||
|
||||
method = service.get_method(method_id)
|
||||
|
||||
if method is None:
|
||||
raise MethodServiceError(
|
||||
"Метод не найден."
|
||||
)
|
||||
|
||||
latest = service.get_latest_method_version(
|
||||
method_id,
|
||||
)
|
||||
|
||||
if latest is None:
|
||||
raise MethodServiceError(
|
||||
"У метода отсутствует версия."
|
||||
)
|
||||
|
||||
if request.method == "POST":
|
||||
try:
|
||||
name = request.form.get(
|
||||
"name",
|
||||
"",
|
||||
).strip()
|
||||
|
||||
description = request.form.get(
|
||||
"description",
|
||||
"",
|
||||
).strip()
|
||||
|
||||
hash_mode_raw = request.form.get(
|
||||
"hash_mode",
|
||||
"22000",
|
||||
).strip()
|
||||
|
||||
if not name:
|
||||
raise MethodServiceError(
|
||||
"Введите название метода."
|
||||
)
|
||||
|
||||
if hash_mode_raw != "22000":
|
||||
raise MethodServiceError(
|
||||
"Сейчас поддерживается только hash mode 22000."
|
||||
)
|
||||
|
||||
steps = _build_steps_from_form()
|
||||
|
||||
definition = {
|
||||
"schema_version": 1,
|
||||
"hash_mode": 22000,
|
||||
"steps": steps,
|
||||
}
|
||||
|
||||
with conn:
|
||||
service.update_method(
|
||||
method_id=method_id,
|
||||
name=name,
|
||||
description=description or None,
|
||||
)
|
||||
|
||||
service.update_method_version(
|
||||
method_id=method_id,
|
||||
version=latest["version"],
|
||||
definition=definition,
|
||||
)
|
||||
|
||||
return redirect(
|
||||
url_for(
|
||||
"cracklab.methods_page",
|
||||
)
|
||||
)
|
||||
|
||||
except (MethodServiceError, ValueError) as exc:
|
||||
error = str(exc)
|
||||
|
||||
definition = json.loads(
|
||||
latest["definition_json"]
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"method_create.html",
|
||||
active_page="methods",
|
||||
error=error,
|
||||
method=method,
|
||||
definition=definition,
|
||||
edit_mode=True,
|
||||
)
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
@cracklab_bp.route("/methods/create/", methods=["GET", "POST"])
|
||||
def method_create_page():
|
||||
|
||||
Reference in New Issue
Block a user