~sircmpwn/pass-rotate

38b2260cdc14fb5bfdbf52d7d8b66383f12ed8b0 — Drew DeVault 3 years ago 5155c94 + 2745d9f
Merge pull request #36 from arunisaac/master

Add Arch User Repository (AUR) provider
3 files changed, 49 insertions(+), 2 deletions(-)

M passrotate/forms.py
M passrotate/providers/__init__.py
A passrotate/providers/aur.py
M passrotate/forms.py => passrotate/forms.py +5 -2
@@ 14,7 14,10 @@ def get_form_data(inputs: ResultSet) -> FormData:
    Returns dictionary with (name, value) pairs from inputs.
    """
    return {
        i.get("name", ""): i.get("value", "") or "" for i in inputs if i.get("name", "")
        i.get("name", ""): \
        i.get("value", "") or "" if i.name == "input" \
        else i.find("option", attrs={"selected": "selected"}).get("value") \
        for i in inputs if i.get("name", "")
    }




@@ 30,7 33,7 @@ def get_form(text: str, type: str = "form", **kwargs) -> FormData:
    """
    soup = BeautifulSoup(text, "html5lib")
    form = soup.find(type, attrs=kwargs)
    inputs = form.find_all("input")
    inputs = form.find_all("input") + form.find_all("select")
    return get_form_data(inputs)



M passrotate/providers/__init__.py => passrotate/providers/__init__.py +1 -0
@@ 14,3 14,4 @@ from passrotate.providers.pypi import PyPI
from passrotate.providers.ankiweb import AnkiWeb
from passrotate.providers.gitlab import GitLab
from passrotate.providers.wikipedia import Wikipedia
from passrotate.providers.aur import ArchUserRepository

A passrotate/providers/aur.py => passrotate/providers/aur.py +43 -0
@@ 0,0 1,43 @@
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests

class ArchUserRepository(Provider):
    """
    [aur.archlinux.org]
    username=Your Arch User Repository username
    """
    name = "Arch User Repository"
    domains = [
        "aur.archlinux.org",
    ]
    options = {
        "username": ProviderOption(str, "Your Arch User Repository username")
    }

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

    def _login(self, old_password):
        login_url = "https://aur.archlinux.org/login/"
        r = self._session.post(login_url, data={"user": self.username, "passwd": old_password})
        if r.status_code != 200:
            raise Exception("Unable to log into your Arch User Repository account with current password")
        return r

    def prepare(self, old_password):
        self._session = requests.Session()
        self._login(old_password)
        password_change_url = "https://aur.archlinux.org/account/" + self.username + "/edit"
        r = self._session.get(password_change_url)
        self._form = get_form(r.text, id="edit-profile-form")

    def execute(self, old_password, new_password):
        post_url = "https://aur.archlinux.org/account/" + self.username + "/update"
        self._form.update({
            "P": new_password,
            "C": new_password
        })
        r = self._session.post(post_url, data=self._form)

register_provider(ArchUserRepository)