~sircmpwn/pass-rotate

e518b9703b1834772def88a4fb4f0c92430ea900 — Pranjal Kole a month ago b4f3c3e master
Add Codeberg.org Provider

2FA support for Codeberg not implemented in this commit.
Codeberg uses a per-session hidden input element as a CSRF token.
2 files changed, 43 insertions(+), 0 deletions(-)

M passrotate/providers/__init__.py
A passrotate/providers/codeberg.py
M passrotate/providers/__init__.py => passrotate/providers/__init__.py +1 -0
@@ 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

A passrotate/providers/codeberg.py => passrotate/providers/codeberg.py +42 -0
@@ 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)