~sircmpwn/pass-rotate

ref: 7a0f1572c61de44c5ceed81c5d65c6830bc45865 pass-rotate/passrotate/providers/ankiweb.py -rw-r--r-- 1.6 KiB
7a0f1572 — Matthias Gabriel add option to override the pass name to be used when rotating the password 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests


class AnkiWeb(Provider):
    """
    [ankiweb.net]
    username=Your AnkiWeb username (email)
    """
    name = "AnkiWeb"
    domains = [
        "ankiweb.net",
    ]
    options = {
        "username": ProviderOption(str, "Your AnkiWeb username")
    }

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

    def prepare(self, old_password):
        self._session = requests.Session()
        r = self._session.get("https://ankiweb.net/account/login")
        self._form = get_form(r.text, id="form")
        self._form.update({
            "username": self.username,
            "password": old_password
        })
        r = self._session.post("https://ankiweb.net/account/login",
                               data=self._form, allow_redirects=False)
        if not r.ok or r.status_code != 302:
            raise Exception("Unable to log into AnkiWeb with current password")
        r = self._session.get("https://ankiweb.net/account/settings")
        self._form = get_form(r.text)

    def execute(self, old_password, new_password):
        self._form.update({
            "oldpw": old_password,
            "pass1": new_password,
            "pass2": new_password
        })
        r = self._session.post("https://ankiweb.net/account/settings",
                               data=self._form, allow_redirects=False)
        if not r.ok or r.status_code != 302:
            raise Exception("Failed to update AnkiWeb password")


register_provider(AnkiWeb)