~sircmpwn/public-inbox

pass-rotate: Add Lichess.org provider v1 APPLIED

Pranjal Kole
Pranjal Kole: 1
 Add Lichess.org provider

 2 files changed, 42 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/public-inbox/patches/25741/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH pass-rotate] Add Lichess.org provider Export this patch

Pranjal Kole
---
 passrotate/providers/__init__.py |  1 +
 passrotate/providers/lichess.py  | 41 ++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 passrotate/providers/lichess.py

diff --git a/passrotate/providers/__init__.py b/passrotate/providers/__init__.py
index 83dc118..df190ef 100644
--- a/passrotate/providers/__init__.py
+++ b/passrotate/providers/__init__.py
@@ -15,3 +15,4 @@ from passrotate.providers.ankiweb import AnkiWeb
from passrotate.providers.gitlab import GitLab
from passrotate.providers.wikipedia import Wikipedia
from passrotate.providers.aur import ArchUserRepository
from passrotate.providers.lichess import Lichess
diff --git a/passrotate/providers/lichess.py b/passrotate/providers/lichess.py
new file mode 100644
index 0000000..0d45bcf
--- /dev/null
+++ b/passrotate/providers/lichess.py
@@ -0,0 +1,41 @@
from passrotate.provider import Provider, ProviderOption, register_provider
from passrotate.forms import get_form
import requests

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

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

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

    def prepare(self, old_password):
        self._session = requests.Session()
        self._login(old_password)

    def execute(self, old_password, new_password):
        password_change_url = "https://lichess.org/account/passwd"
        _form = {
            "oldPasswd": old_password,
            "newPasswd1": new_password,
            "newPasswd2": new_password
        }
        r = self._session.post(password_change_url, data=_form)

register_provider(Lichess)
-- 
2.33.1
Thanks!

To git@git.sr.ht:~sircmpwn/pass-rotate
   f99817e..e518b97  master -> master