~sircmpwn/pass-rotate

ref: 7a0f1572c61de44c5ceed81c5d65c6830bc45865 pass-rotate/passrotate/providers/zotero.py -rw-r--r-- 1.5 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
50
51
from passrotate.provider import Provider, ProviderOption, register_provider
import requests


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

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

    def prepare(self, old_password):
        self._session = requests.Session()
        self._session.get("https://www.zotero.org/user/login")
        r = self._session.post("https://www.zotero.org/user/login", data={
            "username": self.username,
            "password": old_password,
            "remember": 0,
            "login": "",
            "oid_identifier": ""
        })
        if "Invalid credentials provided" in r.text:
            raise Exception("Unable to log into Zotero with current password")
        r = self._session.get("https://www.zotero.org/settings/account")

    def execute(self, old_password, new_password):
        form_data = {
            "password": old_password,
            "new_password": new_password,
            "new_password2": new_password,
            "updatesettings": ""
        }
        r = self._session.post(
            "https://www.zotero.org/settings/account",
            data=form_data, allow_redirects=False
        )
        if "Account Settings Saved" not in r.text:
            raise Exception("Failed to update Zotero password")


register_provider(Zotero)