~sircmpwn/pass-rotate

bf7ae164bec43d715b9a830e48ea9eceb3cc8d99 — Drew DeVault 3 years ago 017673c + e52e5dc 0.1
Merge pull request #35 from arunisaac/wikipedia

Add Wikipedia provider
2 files changed, 52 insertions(+), 1 deletions(-)

M passrotate/providers/__init__.py
A passrotate/providers/wikipedia.py
M passrotate/providers/__init__.py => passrotate/providers/__init__.py +2 -1
@@ 12,4 12,5 @@ from passrotate.providers.facebook import Facebook
from passrotate.providers.zotero import Zotero
from passrotate.providers.pypi import PyPI
from passrotate.providers.ankiweb import AnkiWeb
from passrotate.providers.gitlab import GitLab
\ No newline at end of file
from passrotate.providers.gitlab import GitLab
from passrotate.providers.wikipedia import Wikipedia

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

class Wikipedia(Provider):
    """
    [wikipedia.org]
    username=Your Wikipedia username
    """
    name = "Wikipedia"
    domains = [
        "wikipedia.org",
    ]
    options = {
        "username": ProviderOption(str, "Your Wikipedia username")
    }
    _login_url = "https://en.wikipedia.org/w/index.php?title=Special:UserLogin"
    _password_change_url = "https://en.wikipedia.org/w/index.php?" \
                           "title=Special:ChangeCredentials" \
                           "/MediaWiki\Auth\PasswordAuthenticationRequest"

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

    def _login(self, old_password):
        r = self._session.get(self._login_url)
        form = get_form(r.text)
        form.update({
            "wpName": self.username,
            "wpPassword": old_password
        })
        r = self._session.post(self._login_url, data=form)
        if r.status_code != 200:
            raise Exception("Unable to log into Wikipedia account with current password")
        return r

    def prepare(self, old_password):
        self._session = requests.Session()
        self._login(old_password)
        r = self._session.get(self._password_change_url)
        self._form = get_form(r.text)

    def execute(self, old_password, new_password):
        self._form.update({
            "password": new_password,
            "retype": new_password
        })
        r = self._session.post(self._password_change_url, data=self._form)

register_provider(Wikipedia)