~sircmpwn/public-inbox

pass-rotate: Add Codeberg.org Provider v1 APPLIED

Pranjal Kole: 1
 Add Codeberg.org Provider

 2 files changed, 43 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/25776/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH pass-rotate] Add Codeberg.org Provider Export this patch

2FA support for Codeberg not implemented in this commit.
Codeberg uses a per-session hidden input element as a CSRF token.
---
 passrotate/providers/__init__.py |  1 +
 passrotate/providers/codeberg.py | 42 ++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 passrotate/providers/codeberg.py

diff --git a/passrotate/providers/__init__.py b/passrotate/providers/__init__.py
index df190ef..74e1eb0 100644
--- a/passrotate/providers/__init__.py
+++ b/passrotate/providers/__init__.py
@@ -16,3 +16,4 @@ from passrotate.providers.gitlab import GitLab
from passrotate.providers.wikipedia import Wikipedia
from passrotate.providers.aur import ArchUserRepository
from passrotate.providers.lichess import Lichess
from passrotate.providers.codeberg import Codeberg
diff --git a/passrotate/providers/codeberg.py b/passrotate/providers/codeberg.py
new file mode 100644
index 0000000..06a86f9
--- /dev/null
+++ b/passrotate/providers/codeberg.py
@@ -0,0 +1,42 @@
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests

class Codeberg(Provider):
    """
    [codeberg.org]
    username=Your Codeberg.org username
    """
    name = "Codeberg"
    domains = [
        "codeberg.org",
    ]
    options = {
        "username": ProviderOption(str, "Your Codeberg username")
    }

    def __init__(self, options):
        self.username = options["username"]

    def prepare(self, old_password):
        self._session = requests.Session()
        login_url = "https://codeberg.org/user/login"
        login_form = {
            "user_name": self.username,
            "password": old_password
        }
        self._session.post(login_url, data=login_form)

    def execute(self, old_password, new_password):
        password_change_url = "https://codeberg.org/user/settings/account"
        password_change_form = get_form(self._session.get(password_change_url).text)

        password_change_form.update({
            "old_password": old_password,
            "password": new_password,
            "retype": new_password
        })

        self._session.post(password_change_url, data=password_change_form)

register_provider(Codeberg)
-- 
2.33.1
Thanks!

To git@git.sr.ht:~sircmpwn/pass-rotate
   f99817e..e518b97  master -> master