Skip to content

Commit b441a98

Browse files
committed
send_password_reset_email
1 parent 54dc90b commit b441a98

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

docs/reference/sites.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
.. autofunction:: scapi.session_login
1919

20+
.. autofunction:: scapi.send_password_reset_email
21+
2022
.. autoclass:: scapi.Session
2123

2224
.. autoclass:: scapi.SessionStatus

scapi/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Session,
33
SessionStatus,
44
session_login,
5-
login
5+
login,
6+
send_password_reset_email
67
)
78

89
from .sites.other import (

scapi/sites/session.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import hashlib
4-
from typing import AsyncGenerator, Final, Literal
4+
from typing import AsyncGenerator, Final, Literal, overload
55
import zlib
66
import base64
77
import json
@@ -1071,4 +1071,35 @@ def login(username:str,password:str,load_status:bool=True,*,recaptcha_code:str|N
10711071
Returns:
10721072
_AwaitableContextManager[Session]: await か async with で取得できるセッション
10731073
"""
1074-
return _AwaitableContextManager(_login(username,password,load_status,recaptcha_code=recaptcha_code))
1074+
return _AwaitableContextManager(_login(username,password,load_status,recaptcha_code=recaptcha_code))
1075+
1076+
@overload
1077+
def send_password_reset_email(client:HTTPClient,*,username:str):
1078+
pass
1079+
1080+
@overload
1081+
def send_password_reset_email(client:HTTPClient,*,email:str):
1082+
pass
1083+
1084+
async def send_password_reset_email(client:HTTPClient,*,username:str|None=None,email:str|None=None):
1085+
"""
1086+
パスワードリセットメールを送信する。
1087+
ユーザー名とメールアドレスはどちらかのみ指定できます。
1088+
1089+
Args:
1090+
client (HTTPClient): 通信に使用するHTTPClient
1091+
username (str | None, optional): ユーザー名
1092+
email (str | None, optional): メールアドレス
1093+
"""
1094+
data = aiohttp.FormData({"csrfmiddlewaretoken":"a"})
1095+
if username is not None:
1096+
if email is not None:
1097+
raise ValueError()
1098+
data.add_field("username",username)
1099+
else:
1100+
if email is None:
1101+
raise ValueError()
1102+
data.add_field("email",email)
1103+
response = await client.post("https://scratch.mit.edu/accounts/password_reset/",data=data)
1104+
if response._response.url == "https://scratch.mit.edu/accounts/password_reset/":
1105+
raise InvalidData(response)

0 commit comments

Comments
 (0)