forgejo/models/user
zokki d6838462b8 feat: Global 2FA enforcement (#8753)
resolves #8549

This PR add a config to enforce 2FA for the whole Forgejo instance. It can be configured to `none`, `admin` or `all`.
A user who is required to enable 2FA is like a disabled user. He can only see the `/user/settings/security`-Page to enable 2FA, this should be similar to a user which needs to change his password. Also api and git-commands are not allowed.

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I added test coverage for JavaScript changes...
  - [ ] in `web_src/js/*.test.js` if it can be unit tested.
  - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)).

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [ ] I did not document these changes and I do not expect someone else to do it.

I will do it, if the general idea of this PR is a good feature.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [x] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Security features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/8753): <!--number 8753 --><!--line 0 --><!--description R2xvYmFsIDJGQSBlbmZvcmNlbWVudA==-->Global 2FA enforcement<!--description-->
<!--end release-notes-assistant-->

Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8753
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Ellen Εμιλία Άννα Zscheile <fogti@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: zokki <zokki.softwareschmiede@gmail.com>
Co-committed-by: zokki <zokki.softwareschmiede@gmail.com>
2025-08-15 10:56:45 +02:00
..
fixtures feat: add option to allow non-local users to change usernames (#8714) 2025-08-06 20:25:13 +02:00
activitypub.go Improved signature handling & instance actor (#8275) 2025-07-01 19:49:00 +02:00
avatar.go Return default avatar url when user id is zero rather than updating database (#34094) 2025-04-07 16:48:15 +02:00
avatar_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
badge.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
block.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
block_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
email_address.go chore(sec): unify usage of crypto/rand.Read (#7453) 2025-04-04 03:31:37 +00:00
email_address_test.go fix: user activation with uppercase email address (#8367) 2025-07-02 13:04:22 +02:00
error.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
external_login_user.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
federated_user.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
federated_user_follower.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
federated_user_follower_test.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
federated_user_test.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
follow.go fix: assorted ActivityPub code only refactors (#8708) 2025-07-28 15:17:29 +02:00
follow_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
list.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
main_test.go chore: merge tests.AddFixtures and unittest.OverrideFixtures (#7648) 2025-04-25 09:14:33 +00:00
moderation.go feat: Admin interface for abuse reports (#7905) 2025-07-23 00:20:15 +02:00
moderation_test.go feat: Admin interface for abuse reports (#7905) 2025-07-23 00:20:15 +02:00
must_change_password.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
openid.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
openid_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
redirect.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
redirect_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
search.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
setting.go chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
setting_keys.go Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
setting_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
user.go feat: Global 2FA enforcement (#8753) 2025-08-15 10:56:45 +02:00
user_repository.go fix: assorted ActivityPub code only refactors (#8708) 2025-07-28 15:17:29 +02:00
user_system.go fix: only send Forgejo Actions notifications to one user (#8227) 2025-06-21 12:15:38 +02:00
user_test.go feat: Global 2FA enforcement (#8753) 2025-08-15 10:56:45 +02:00
user_update.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00