-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
app/src/main/java/it/chalmers/gamma/adapter/primary/web/DeleteYourAccountController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package it.chalmers.gamma.adapter.primary.web; | ||
|
||
import it.chalmers.gamma.app.user.MeFacade; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
@Controller | ||
public class DeleteYourAccountController { | ||
|
||
private final MeFacade meFacade; | ||
|
||
public DeleteYourAccountController(MeFacade meFacade) { | ||
this.meFacade = meFacade; | ||
} | ||
|
||
public record DeleteYourAccountForm(String password) {} | ||
|
||
@GetMapping("/delete-your-account") | ||
public ModelAndView getDeleteYourAccount( | ||
@RequestHeader(value = "HX-Request", required = false) boolean htmxRequest) { | ||
ModelAndView mv = new ModelAndView(); | ||
|
||
if (htmxRequest) { | ||
mv.setViewName("pages/delete-your-account"); | ||
} else { | ||
mv.setViewName("index"); | ||
mv.addObject("page", "pages/delete-your-account"); | ||
} | ||
|
||
mv.addObject("form", new DeleteYourAccountForm("")); | ||
|
||
return mv; | ||
} | ||
|
||
@DeleteMapping("/delete-your-account") | ||
public ModelAndView deleteYourAccount( | ||
DeleteYourAccountForm form, final BindingResult bindingResult) { | ||
try { | ||
this.meFacade.deleteMe(form.password); | ||
} catch (IllegalArgumentException e) { | ||
bindingResult.addError( | ||
new FieldError("form", "password", "Incorrect password")); | ||
|
||
ModelAndView mv = new ModelAndView(); | ||
|
||
mv.setViewName("pages/delete-your-account"); | ||
mv.addObject("form", new DeleteYourAccountForm("")); | ||
mv.addObject(BindingResult.MODEL_KEY_PREFIX + "form", bindingResult); | ||
|
||
return mv; | ||
} | ||
|
||
return new ModelAndView("redirect:/login?deleted"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/resources/templates/pages/delete-your-account.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<header th:replace="~{common/header}"></header> | ||
<main> | ||
<article> | ||
<header> | ||
Deleting your account | ||
</header> | ||
<p> | ||
Deleting your account can't be reversed. | ||
</p> | ||
<form th:object="${form}" id="delete-account" th:action="@{/delete-your-account}" th:method="delete"> | ||
<div th:replace="~{common/input :: passwordTextInput2(field='password', label='Confirm password')}"></div> | ||
</form> | ||
<footer> | ||
<button form="delete-account"> | ||
Delete the account | ||
</button> | ||
</footer> | ||
</article> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,4 +78,25 @@ | |
<button disabled class="outline" form="update-me-avatar">Upload avatar</button> | ||
</footer> | ||
</article> | ||
<article> | ||
<header> | ||
Do you want to delete your account? | ||
</header> | ||
<p> | ||
Here you can delete your account and prevent further access for clients you have accepted. | ||
You have the right to ensure all of your data is removed. | ||
Please email <a href="mailto:[email protected]">[email protected]</a>, along with: | ||
</p> | ||
<p> | ||
UserId: <span th:text="${me.id()}"></span> | ||
</p> | ||
<p> | ||
Cid: <span th:text="${me.cid()}"></span> | ||
</p> | ||
<footer> | ||
<a th:href="@{/delete-your-account}" > | ||
Proceed to deleting your account | ||
</a> | ||
</footer> | ||
</article> | ||
</main> |