Magic Poi Lite 0.1
IOT LED Poi
|
Public Member Functions | |
Authentication () | |
Default constructor for Authentication class. | |
String | readJWTTokenFromFile () |
Reads JWT token from a file stored on LittleFS. | |
void | saveJWTTokenToFile (const char *token) |
Saves a JWT token to a file on LittleFS. | |
bool | authenticate () |
Authenticates the client with the server. | |
bool | checkSavedToken () |
Checks for a saved JWT token and loads it if available. | |
Private Attributes | |
char | token [500] |
Buffer for JWT token. | |
char | jwtToken [500] |
Buffer for JWT token. | |
boolean | gotToken = false |
Flag indicating whether a token has been retrieved. | |
const char * | jwtFilePath = "/jwt.txt" |
Path to the file storing JWT token. | |
WiFiClient | client |
WiFi client object. | |
Authentication::Authentication | ( | ) |
Default constructor for Authentication class.
This constructor initializes the Authentication object by clearing the jwtToken buffer.
References jwtToken.
bool Authentication::authenticate | ( | ) |
Authenticates the client with the server.
This method attempts to authenticate the client with the server by sending a POST request to the login endpoint with the provided email and password. If the authentication is successful, the JWT token received from the server is parsed and saved, and the method returns true. If any error occurs during the HTTP request or JSON parsing, or if the server returns an error response code, the method returns false.
References client, gotToken, saveJWTTokenToFile(), and token.
Referenced by handleAuthenticationAndLoading().
bool Authentication::checkSavedToken | ( | ) |
Checks for a saved JWT token and loads it if available.
This method checks if a JWT token is saved in a file. If a token is found, it loads the token into the internal token buffer. If no token is found, the method returns false.
References gotToken, readJWTTokenFromFile(), and token.
Referenced by handleAuthenticationAndLoading().
String Authentication::readJWTTokenFromFile | ( | ) |
Reads JWT token from a file stored on LittleFS.
This method attempts to read a JWT token from a file stored on LittleFS (Little File System). If the file exists, it reads the token from the file and returns it. If the file does not exist or if there's any failure during the file system operation, an empty string is returned.
References jwtFilePath, and jwtToken.
Referenced by checkSavedToken(), and Loading::Loading().
void Authentication::saveJWTTokenToFile | ( | const char * | token | ) |
Saves a JWT token to a file on LittleFS.
This method attempts to save a JWT token to a file stored on LittleFS (Little File System). If LittleFS initialization succeeds and the file is successfully created and written, a success message is printed to the Serial monitor. If there's any failure during the file system operation, an error message is printed.
token | The JWT token to be saved to the file. |
References jwtFilePath, and token.
Referenced by authenticate().
|
private |
WiFi client object.
This object is used for network communication with the server.
Referenced by authenticate().
|
private |
Path to the file storing JWT token.
This string represents the file path of the file storing the JWT token in LittleFS.
Referenced by readJWTTokenFromFile(), and saveJWTTokenToFile().
|
private |
Buffer for JWT token.
This buffer stores the JWT token retrieved from LittleFS.
Referenced by Authentication(), and readJWTTokenFromFile().
|
private |
Buffer for JWT token.
This buffer stores the JWT token retrieved from authentication.
Referenced by authenticate(), checkSavedToken(), and saveJWTTokenToFile().