1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*!
* The auth_routes module for handling user authentication and registration.
*
* This module defines the routes for user login and registration, including
* the necessary input and output structures. It uses Actix Web for routing
* and SQLx for database interaction.
*/
use ;
use crate;
use crate;
/**
* Configure routes for user authentication and registration.
*
* This function sets up the routes for user login and registration, using
* Actix Web's `ServiceConfig`. It also applies middleware for JWT validation.
*
* # Arguments
* - `cfg`: A mutable reference to the Actix Web `ServiceConfig`.
*/
/**
* Login route handler.
*
* This function handles user login requests. It extracts the login input
* from the request, calls the `login_user` function to authenticate the user,
* and returns a JSON response with the login token or an error message.
*
* # Arguments
* - `pool`: A reference to the SQLx SQLite connection pool.
* - `input`: The login input data, containing the username and password.
*
* # Returns
* An `HttpResponse` containing the login token or an error message.
*/
async
/**
* Register route handler.
*
* This function handles user registration requests. It extracts the registration
* input from the request, calls the `register_user` function to create a new user,
* and returns a JSON response with the user data or an error message.
*
* # Arguments
* - `pool`: A reference to the SQLx SQLite connection pool.
* - `input`: The registration input data, containing the username and password.
*
* # Returns
* An `HttpResponse` containing the user data or an error message.
*/
async