This repository has been archived on 2024-01-13. You can view files and clone it, but cannot push or open issues or pull requests.
arka-mvp/api/api_methods.py

77 lines
2.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from .api_errors import *
from .api_utils import *
from .models import *
def _reqire_access_token(params):
token = api_get_param_str(params, "access_token")
return UserToken.get_user_by_token(token)
def make_response(response):
return {"response": response}
def account_auth(params):
login = api_get_param_str(params, "login")
password = api_get_param_str(params, "password")
user = UserToken.auth(login, password)
token = UserToken.create_token(user)
return make_response({"access_token": token.access_token})
def account_register(params):
pass
def account_get(params):
user = _reqire_access_token(params)
return make_response({"name": user.name, "surname": user.surname, "email": user.email, "phone": user.phone})
def __make_argument_doc(name, arg_type, description, required=True):
return {
"name": name,
"type": arg_type,
"description": description,
"required": required
}
def __make_argument_access_token():
return __make_argument_doc("access_token", "string", "<i>Токен</i>, выданный методом <code>account.auth</code>")
__doc_type_string = "string"
api_methods = {
"account.auth": {
"func": account_auth,
"doc": "Аутентификация пользователя",
"params": [
__make_argument_doc("login", __doc_type_string, "Логин пользователя"),
__make_argument_doc("password", __doc_type_string, "Пароль пользователя"),
],
"returns": "В случае правильных логина и пароля <code>access_token</code>. В противном случае объект ошибки."
},
"account.register": {
"func": account_register,
"doc": "Регистрация нового пользователя",
"params": [
],
"returns": "Поля пользователя (name, surname, email, phone)."
},
"account.get": {
"func": account_get,
"doc": "Получение информации о пользователе",
"params": [
__make_argument_access_token()
],
"returns": "Поля пользователя (name, surname, email, phone)."
},
}