{"id":16417458,"url":"https://github.com/artinnok/django-swap-user","last_synced_at":"2025-09-05T19:04:22.756Z","repository":{"id":37745950,"uuid":"281922887","full_name":"artinnok/django-swap-user","owner":"artinnok","description":"(Beta) Simple and flexible way to swap default Django User","archived":false,"fork":false,"pushed_at":"2023-11-22T16:37:00.000Z","size":140,"stargazers_count":62,"open_issues_count":2,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-31T06:39:47.168Z","etag":null,"topics":["authentication","django","otp","otp-verification","python","user","user-management"],"latest_commit_sha":null,"homepage":"https://skonik.github.io/django-swap-user-docs/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/artinnok.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-23T10:36:39.000Z","updated_at":"2023-09-08T20:39:32.000Z","dependencies_parsed_at":"2024-10-11T07:12:05.296Z","dependency_job_id":"e8e3916b-2f04-4695-b9e4-f24af2aee0c7","html_url":"https://github.com/artinnok/django-swap-user","commit_stats":{"total_commits":147,"total_committers":6,"mean_commits":24.5,"dds":0.08843537414965985,"last_synced_commit":"582f4d62e2f9cf1bf90c4bc146e068163587fefd"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/artinnok/django-swap-user","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artinnok%2Fdjango-swap-user","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artinnok%2Fdjango-swap-user/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artinnok%2Fdjango-swap-user/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artinnok%2Fdjango-swap-user/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artinnok","download_url":"https://codeload.github.com/artinnok/django-swap-user/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artinnok%2Fdjango-swap-user/sbom","scorecard":{"id":209572,"data":{"date":"2025-08-11","repo":{"name":"github.com/artinnok/django-swap-user","commit":"582f4d62e2f9cf1bf90c4bc146e068163587fefd"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.7,"checks":[{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/publish.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/test.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/test.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:33: update your workflow using https://app.stepsecurity.io/secureworkflow/artinnok/django-swap-user/test.yml/master?enable=pin","Info:   0 out of   5 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":2,"reason":"Found 6/23 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/publish.yml:1","Warn: no topLevel permission defined: .github/workflows/test.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 13 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"32 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2024-48 / GHSA-fj7x-q9j7-g6q6","Warn: Project is vulnerable to: PYSEC-2024-230 / GHSA-248v-346w-9cwc","Warn: Project is vulnerable to: PYSEC-2022-42986 / GHSA-43fp-rhv2-5gv8","Warn: Project is vulnerable to: PYSEC-2023-135 / GHSA-xqr8-7jwr-rhp7","Warn: Project is vulnerable to: PYSEC-2023-13 / GHSA-2hrw-hx67-34x6","Warn: Project is vulnerable to: PYSEC-2023-225 / GHSA-7h4p-27mh-hmrw","Warn: Project is vulnerable to: GHSA-7xr5-9hcq-chf9","Warn: Project is vulnerable to: PYSEC-2022-245 / GHSA-8x94-hmjh-97hq","Warn: Project is vulnerable to: PYSEC-2023-226 / GHSA-h8gc-pgj2-vjm3","Warn: Project is vulnerable to: PYSEC-2023-100 / GHSA-jh3w-4vvf-mjgr","Warn: Project is vulnerable to: PYSEC-2022-213 / GHSA-p64x-8rxx-wf6q","Warn: Project is vulnerable to: PYSEC-2023-12 / GHSA-q2jf-h9jm-m7p4","Warn: Project is vulnerable to: PYSEC-2023-222 / GHSA-qmf9-6jqf-j8fq","Warn: Project is vulnerable to: PYSEC-2022-304 / GHSA-qrw5-5h28-6cmg","Warn: Project is vulnerable to: PYSEC-2023-61 / GHSA-r3xc-prgr-mg9p","Warn: Project is vulnerable to: GHSA-rrqc-c2jx-6jgv","Warn: Project is vulnerable to: PYSEC-2024-47 / GHSA-vm8q-m57g-pff3","Warn: Project is vulnerable to: PYSEC-2024-28 / GHSA-xxj9-f6rv-m3x4","Warn: Project is vulnerable to: PYSEC-2022-301 / GHSA-8fg9-p83m-x5pq","Warn: Project is vulnerable to: PYSEC-2024-60 / GHSA-jjg7-2v4v-x38h","Warn: Project is vulnerable to: PYSEC-2022-42969","Warn: Project is vulnerable to: GHSA-9hjg-9r4m-mvj7","Warn: Project is vulnerable to: GHSA-9wx4-h78v-vm56","Warn: Project is vulnerable to: PYSEC-2023-74 / GHSA-j8r2-6x86-q33q","Warn: Project is vulnerable to: GHSA-2m57-hf25-phgg","Warn: Project is vulnerable to: PYSEC-2023-87 / GHSA-rrm6-wvj7-cwh2","Warn: Project is vulnerable to: GHSA-34jh-p97f-mpxf","Warn: Project is vulnerable to: PYSEC-2023-212 / GHSA-g4mx-q9vg-27p4","Warn: Project is vulnerable to: GHSA-pq67-6m6q-mj2v","Warn: Project is vulnerable to: PYSEC-2023-192 / GHSA-v845-jxx5-vc9f","Warn: Project is vulnerable to: PYSEC-2024-187 / GHSA-rqc4-2hc7-8c8v","Warn: Project is vulnerable to: GHSA-jfmj-5v4g-7637"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T00:30:25.921Z","repository_id":37745950,"created_at":"2025-08-17T00:30:25.921Z","updated_at":"2025-08-17T00:30:25.921Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273805688,"owners_count":25171560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","django","otp","otp-verification","python","user","user-management"],"created_at":"2024-10-11T07:11:31.246Z","updated_at":"2025-09-05T19:04:22.702Z","avatar_url":"https://github.com/artinnok.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Django-Swap-User (Beta)\n![django-swap-user](https://skonik.github.io/django-swap-user-docs/media/images/django-swap-user.png)\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/artinnok/django-user-swap/actions/workflows/test.yml\"\u003e\n    \u003cimg alt=\"test\" src=\"https://github.com/artinnok/django-user-swap/actions/workflows/test.yml/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/skonik/django-swap-user-docs/actions/workflows/main.yml\"\u003e\n    \u003cimg alt=\"docs\" src=\"https://github.com/skonik/django-swap-user-docs/actions/workflows/main.yml/badge.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/django-swap-user/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/pypi-v0.9.8-green\" alt=\"PyPi\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\nIf you are tired of copying one custom user model from one project to another - use this package.\nThis will do it all for you.\n\n## Documentation\nAll official documentation hosted [here](https://skonik.github.io/django-swap-user-docs/).\nThe documentation repo is located [here](https://github.com/skonik/django-swap-user-docs).\n\n## Installation\n```\npip install django-swap-user\n```\n\n## Basic usage\n1. Choose a model that suits you and copy related settings from the table:\n\n| Application name | Username field | Description                                                            | `INSTALLED_APPS`                               | `AUTH_USER_MODEL`                      | Replace `django.contrib.admin` to          |\n|------------------|----------------|------------------------------------------------------------------------|------------------------------------------------|----------------------------------------|--------------------------------------------|\n| `to_email`       | `email`        | User with `email` username                                             | ```\"swap_user\", \"swap_user.to_email\",```       | `\"swap_to_email.EmailUser\"`            | not required                               |                                  \n| `to_email_otp`   | `email`        | User with `email` username, without `password` and OTP authentication  | ```\"swap_user\", \"swap_user.to_email_otp\",```   | `\"swap_to_email_otp.EmailOTPUser\"`     | `\"swap_user.apps.OTPSiteConfig\"`           |\n| `to_phone`       | `phone`        | User with `phone` username                                             | ```\"swap_user\", \"swap_user.to_phone\",```       | `\"swap_to_phone.PhoneUser\"`            | not required                               |                                            \n| `to_phone_otp`   | `phone`        | User with `phone` username, without `password`  and OTP authentication | ```\"swap_user\", \"swap_user.to_phone_otp\",```   | `\"swap_to_phone_otp.PhoneOTPUser\"`     | `\"swap_user.apps.OTPSiteConfig\"`           |\n\n2. Add corresponding app to `INSTALLED_APPS`:\n```python\nINSTALLED_APPS = [\n    ...\n    \"swap_user\",\n    \"swap_user.to_email\",\n    ...\n]\n```\n\n3. Change `AUTH_USER_MODEL` to corresponding:\n```python\nAUTH_USER_MODEL = \"swap_to_email.EmailUser\"\n```\n\n4. If required replace `django.contrib.admin` in `INSTALLED_APPS` to something.\n\n5. Apply migrations:\n```bash\npython manage.py migrate swap_to_email\n```\n\n\n## Architecture\nApplication `swap_user` split into 3 apps:\n  - `to_email` - provides user with `email` username field\n  - `to_email_otp` - provides user with `email` username field and OTP (One Time Password) authentication\n  - `to_phone` - provides user with `phone` username field\n  - `to_phone_otp` - provides user with `phone` username field and OTP (One Time Password) authentication\n  \n  \n## Why the unusual architecture?\nBecause if we leave them in one app, they all will create migrations and tables - such approach leads us to redundant tables.\nThey will be treated as 3 custom models within the same app, which causes perplexing and cognitive burden.\n\nWith such approach (when there is a common app which contains internal apps) - the user \ncan choose to connect with the specific user model which is most applicable for concrete business-logic. \n\nI have found such approach at Django REST Framework `authtoken` application and decide to use it - reference is [here](https://github.com/encode/django-rest-framework/tree/master/rest_framework/authtoken).\n\n\n## Providing User model at start of project\nWhen you are starting a project from zero or scratch - this is a best moment to provide custom User model.\nBecause you have't a lot of migrations or you can easily regenerate them. Moreover, Django's [official docs](https://docs.djangoproject.com/en/dev/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project)\nrecommend to provide custom User model even if you are fully satisfied with default one - in future it will be easier to extend custom model that fits into your business cases.\n\n\n## Providing User model at mid of project\nThis is a harder way of doing things, but it is still possible to do:\n- Do all the steps at testing database and ONLY IF all of them was successful - try to apply at production environment\n- Please note that these steps are **common** - they fit in most cases, but in some circumstances you need act on situation.\n- Create a backup of your database\n- Add stable tag into your repository or save a commit hash reference\n- Pray to the heavens\n- Remove all of yours migrations in every app of Django's project\n- Remove all records from `django_migrations` table, for example with SQL `TRUNCATE django_migrations`\n- Now we have a \"clean\" state, so we can change default model\n- Generate new migrations for all of your applications - `python manage.py makemigrations` \n- Now we need to [fake migrate](https://docs.djangoproject.com/en/4.0/ref/django-admin/#cmdoption-migrate-fake) because we already have all the tables with data\n- First fake the `auth` application because we are depending from this one - `python manage.py migrate --fake auth`\n- Install this library, follow instructions and apply migrations\n- Then fake rest of migrations we have - `python manage.py migrate --fake`\n- Run your application!\n\n\n## Development\nIf you want to contribute in this project please consider the following instruction.\n\n### Project setup for development\n\n1. `poetry install` to install poetry deps;\n\n2. `pre-commit install` to install git hooks;\n\n\n### Commands useful in development\nYou can execute a bunch of useful commands located inside `Makefile`:\n\n* `make lint` - run code quality tools such as flake8, isort, safety;\n* `make format` - format your code using black and isort;\n* `make test` - run tests;\n\n\n### Sponsor\n[django-swap-user](https://evrone.com/django-swap-user?utm_source=github\u0026utm_medium=django-swap-user) project is created \u0026 supported by [Evrone](https://evrone.com?utm_source=github\u0026utm_medium=django-swap-user)\n\n[\u003cimg src=\"https://evrone.com/logo/evrone-sponsored-logo.png\" width=300\u003e](https://evrone.com?utm_source=github\u0026utm_medium=python-guidelines)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartinnok%2Fdjango-swap-user","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartinnok%2Fdjango-swap-user","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartinnok%2Fdjango-swap-user/lists"}