Delete duplicated in core_sys_info.py:

- imports
- users_info(), pasword_policy(), password_expiry() --> now in core_user.py
Move password_confirm() from core_sys_info.py to core_user.py
Update README.md
Update requirements.txt --> Added cryptography module
This commit is contained in:
fboissadier
2025-01-21 00:49:41 +01:00
parent 9e048bf98f
commit 28ab1f2d07
4 changed files with 49 additions and 74 deletions

View File

@ -558,4 +558,40 @@ class User(base_api.BaseApi):
"enable_mail_notification": enable_mail_notification,
"never_expired_list": json.dumps(never_expired_list)
}
return self.request_data(api_name, api_path, req_param)
return self.request_data(api_name, api_path, req_param)
def password_confirm(self, password: str) -> dict[str, object] | str:
"""Issues a passowrd/session comparison to ensure the given password matches the auth of the current session.
This is needed by some APIs as a confirmation method, for example, when creating/modifying a scheduled task with root permissions.
Please note that the password will be sent in plain text, just like in the base auth method.
Args:
password (str):
The password with which the session was initiated.
Returns:
dict|str:
A dictionary containing a `SynoConfirmPWToken`, or an error message.
Example return:
{
"data": {
"SynoConfirmPWToken": "xxxxx"
},
"success": true
}
"""
api_name = 'SYNO.Core.User.PasswordConfirm'
info = self.core_list[api_name]
api_path = info['path']
req_param = {'version': info['maxVersion'], 'method': 'auth'}
# Using https
if self.session._secure:
req_param.update({"password": password})
# Using http and self encrypted
else:
req_param.update(self.session.encrypt_params({"password": password}))
return self.request_data(api_name, api_path, req_param, method="post")