Fonctionnement de l’API

Module contents

Module API de l’application TerriStory

Modules principaux

actions module

api module

auth module

Module dédié à la partie d’authentification JWT de l’application.

async authenticate(request, region)

Authenticate a user inside current region with login and password.

Paramètres
  • request (sanic request) – must contain json args with login and password keys

  • region (str) – region key

Renvoie

contains user_id structured as follows:

``` {

 »user_id »: {

« mail »: login, « region »: region

}

Type renvoyé

dict

Lève
  • exceptions.AuthenticationFailed – when json params are missing

  • exceptions.AuthenticationFailed – when login or password are missing

  • exceptions.AuthenticationFailed – when user is not found

  • exceptions.AuthenticationFailed – when password is incorrect

async extra_payload(payload: dict, *args, **kwargs)

Add information on current user inside JWT payload.

Paramètres

payload (dict) – contains at least the user_id information (region and mail)

Renvoie

new payload updated with user data (prenom, nom, mail, etc.)

Type renvoyé

dict

async retrieve_refresh_token(request, user_id, *args, **kwargs)

Retrieve and check the refresh token for a specific account.

Paramètres

user_id (dict) – must contain region and mail keys with user info

async retrieve_user(request, payload: dict, *args, **kwargs)

Retrieve user information from database and return it (used in /auth/me URL)

Paramètres

payload (dict) – must contain region and mail keys with user info

Renvoie

object with user information

Type renvoyé

User

async store_refresh_token(user_id, refresh_token, request, *args, **kwargs)

Store the refresh token for a specific account.

Function called at each authentication, delete old refresh token, if any, and create a new one.

Paramètres

user_id (dict) – must contain region and mail keys with user info

territorialsynthesis module

create_user module

user module

Blueprint for user

async authenticate_user(request, region)
async check_token_captcha(token)
async create_user(request, region)

Create a new user

You can create a new user via the registration form. The account is not enabled by default. It is the admin, after receiving an e-mail, who must validate the account (see the “active” field).

Paramètres

region (str) – region key

Renvoie

user login (mail)

Type renvoyé

str

generate_password()

Generate a new random password.

Renvoie

new password between 8 and 16 characters.

Type renvoyé

str

async regenerate_password(request, region)

Request a new password for a user.

Send a mail with new password saved.

Paramètres

region (str) – region key

Contrôleurs de l’API

Quelques informations sur les contrôleurs de l’API…

Éléments des contrôleurs de l’API

Intégration

Idem sur le module integration.

Éléments du module d’intégration