Typo; easier QR code png saving
This commit is contained in:
parent
805addf18a
commit
b0fccc34cd
2 changed files with 23 additions and 12 deletions
|
@ -205,26 +205,19 @@ and a plain secret code.
|
|||
- Enter this code into your 2FA application
|
||||
**or** save the QR into a file:
|
||||
```python
|
||||
import base64
|
||||
|
||||
url = response.get('secret', '')
|
||||
encoded = url.removeprefix('data:image/png;base64,')
|
||||
|
||||
png = base64.b64decode(encoded)
|
||||
|
||||
with open('test.png', 'wb') as f:
|
||||
f.write(png)
|
||||
>>> qr = response.get('qrcode', '')
|
||||
>>> at.save_qr(qr, 'test.png')
|
||||
```
|
||||
|
||||
- Confirm:
|
||||
```python
|
||||
at.enable_2fa(123456)
|
||||
>>> at.enable_2fa(123456)
|
||||
```
|
||||
Where 123456 is an OTP code from the app.
|
||||
|
||||
### Disable 2FA
|
||||
It's pretty easy:
|
||||
```python
|
||||
at.disable_2fa(123456)
|
||||
>>> at.disable_2fa(123456)
|
||||
```
|
||||
And, of course, pass a real OTP code as an argument.
|
||||
|
|
|
@ -6,6 +6,8 @@ import re
|
|||
import hashlib
|
||||
import logging
|
||||
|
||||
import base64
|
||||
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
import lxml.html
|
||||
|
@ -397,8 +399,24 @@ class Client:
|
|||
'https://aternos.org/panel/ajax/account/secret.php',
|
||||
'GET', sendtoken=True
|
||||
).json()
|
||||
|
||||
def save_qr(self, qrcode: str, filename: str) -> None:
|
||||
|
||||
def enbale_2fa(self, code: int) -> None:
|
||||
"""Writes a 2FA QR code into a png-file
|
||||
|
||||
Args:
|
||||
qrcode (str): Base64 encoded png image from `qrcode_2fa()`
|
||||
filename (str): Where the QR code image must be saved.
|
||||
Existing file will be rewritten.
|
||||
"""
|
||||
|
||||
data = qrcode.removeprefix('data:image/png;base64,')
|
||||
png = base64.b64decode(data)
|
||||
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(png)
|
||||
|
||||
def enable_2fa(self, code: int) -> None:
|
||||
|
||||
"""Enables Two-Factor Authentication
|
||||
|
||||
|
|
Reference in a new issue