gitforge/templates/user/settings/security/twofa.tmpl
Gusted a4642af51a feat: replace cross origin protection (#9830)
Replace the anti-CSRF token with a [cross origin protection by Go](https://go.dev/doc/go1.25#nethttppkgnethttp) that uses a stateless way of verifying if a request was cross origin or not. This allows is to remove al lot of code and replace it with a few lines of code and we no longer have to hand roll this protection. The new protection uses indicators by the browser itself that indicate if the request is cross-origin, thus we no longer have to take care of ensuring the generated CSRF token is passed back to the server any request by the the browser will have send this indicator.

Resolves forgejo/forgejo#3538

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9830
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
2025-10-29 22:43:22 +01:00

43 lines
2 KiB
Go HTML Template

<h4 class="ui top attached header">
{{ctx.Locale.Tr "settings.twofa"}}
</h4>
<div class="ui attached segment">
<p>{{ctx.Locale.Tr "settings.twofa_desc"}}</p>
{{if .TOTPEnrolled}}
<p>{{ctx.Locale.Tr "settings.twofa_is_enrolled"}}</p>
<div class="inline field">
<p>{{ctx.Locale.Tr "settings.twofa_reenroll.description"}}</p>
<a class="ui primary button" href="{{AppSubUrl}}/user/settings/security/two_factor/reenroll">{{ctx.Locale.Tr "settings.twofa_reenroll"}}</a>
</div>
<form class="ui form" action="{{AppSubUrl}}/user/settings/security/two_factor/regenerate_scratch" method="post" enctype="multipart/form-data">
<p>{{ctx.Locale.Tr "settings.regenerate_scratch_token_desc"}}</p>
<button class="ui primary button">{{ctx.Locale.Tr "settings.twofa_scratch_token_regenerate"}}</button>
</form>
{{if .SignedUser.MustHaveTwoFactor}}
<p class="tw-mt-4 tw-mb-0">{{ctx.Locale.Tr "settings.twofa_unroll_unavailable"}}</p>
{{else}}
<form class="ui form" action="{{AppSubUrl}}/user/settings/security/two_factor/disable" method="post" enctype="multipart/form-data" id="disable-form">
<p>{{ctx.Locale.Tr "settings.twofa_disable_note"}}</p>
<button class="ui red button delete-button" data-modal-id="disable-twofa" data-type="form" data-form="#disable-form">{{ctx.Locale.Tr "settings.twofa_disable"}}</button>
</form>
{{end}}
{{else}}
{{/* The recovery tip is there as a means of encouraging a user to enroll */}}
<p>{{ctx.Locale.Tr "settings.twofa_recovery_tip"}}</p>
<p>{{ctx.Locale.Tr "settings.twofa_not_enrolled"}}</p>
<div class="inline field">
<a class="ui primary button" href="{{AppSubUrl}}/user/settings/security/two_factor/enroll">{{ctx.Locale.Tr "settings.twofa_enroll"}}</a>
</div>
{{end}}
<div class="ui g-modal-confirm delete modal" id="disable-twofa">
<div class="header">
{{svg "octicon-trash"}}
{{ctx.Locale.Tr "settings.twofa_disable"}}
</div>
<div class="content">
<p>{{ctx.Locale.Tr "settings.twofa_disable_desc"}}</p>
</div>
{{template "base/modal_actions_confirm" .}}
</div>
</div>