diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 356450f7..de2d4f1b 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -221,6 +221,26 @@ class ProjectForm(EditProjectForm): raise ValidationError(Markup(message)) +class DeleteProjectForm(FlaskForm): + password = PasswordField( + _("Private code"), + description=_("Enter private code to confirm deletion"), + validators=[DataRequired()], + ) + + def __init__(self, *args, **kwargs): + # Same trick as EditProjectForm: we need to know the project ID + self.id = SimpleNamespace(data=kwargs.pop("id", "")) + super().__init__(*args, **kwargs) + + def validate_password(form, field): + project = Project.query.get(form.id.data) + if project is None: + raise ValidationError(_("Unknown error")) + if not check_password_hash(project.password, form.password.data): + raise ValidationError(_("Invalid private code.")) + + class AuthenticationForm(FlaskForm): id = StringField(_("Project identifier"), validators=[DataRequired()]) password = PasswordField(_("Private code"), validators=[DataRequired()]) diff --git a/ihatemoney/static/css/main.css b/ihatemoney/static/css/main.css index 3a6630bf..ef459c42 100644 --- a/ihatemoney/static/css/main.css +++ b/ihatemoney/static/css/main.css @@ -303,11 +303,6 @@ footer .footer-left { color: #fff; } -.confirm, -.confirm:hover { - color: red; -} - .bill-actions { padding-top: 10px; text-align: center; diff --git a/ihatemoney/templates/edit_project.html b/ihatemoney/templates/edit_project.html index 478b7b42..f2fffb20 100644 --- a/ihatemoney/templates/edit_project.html +++ b/ihatemoney/templates/edit_project.html @@ -1,9 +1,17 @@ {% extends "layout.html" %} {% block js %} - $('#delete-project').click(function () - { - $(this).html("{{_("you sure?")}}"); + + $('#delete-project').click(function(){ + var link = $(this).find('button'); + link.click(function(){ + if ($(this).hasClass("confirm")){ + return true; + } + $(this).html("{{_("Are you sure?")}}"); + $(this).addClass("confirm"); + return false; + }); }); $('.custom-file-input').on('change', function(event) { @@ -21,6 +29,10 @@ {{ forms.edit_project(edit_form) }} +