go to private/constants/system_constants.php and set loggedIn to false. The dev_token is tied to user_id 19 in the db. if you cant find routes, its possible ur accessing non-authenticated routes while you're already logged into our dev environment so its looking for a token.
also, you need to create dbconfig.php, i have provided connection details in messages.
Associated files:
public_html/index.php
`private/classes/class.router.php
Adds a new route to the router.
$uri
- The route URI$controller
- The controller name and method, separated by @
$requestMethod
- The HTTP request method@
. If not, throw an exception.@
. If not, throw an exception.Now, we can specify required parameters for different HTTP request methods (e.g., GET, POST, PUT) for each route. This ensures that the necessary data is present when handling requests.
Example:
// Update an existing integration for the authenticated user
$router->enforceParameters('/integrations/:id', 'PUT', [
'service' => 'body', // Service comes from the request body
'clientname' => 'body', // Service comes from the request body
]);
We've added support for documenting our routes comprehensively. We can include documentation for each route, describing its purpose and usage.
Example:
// Add documentation to route
$router->addDocumentation('/integrations/:id', 'PUT', 'Updates an existing integration for the authenticated user.');
Now, we can specify required parameters for different HTTP request methods (e.g., GET, POST, PUT) for each route. This ensures that the necessary data is present when handling requests.
Example:
// Update an existing integration for the authenticated user
$router->enforceParameters('/integrations/:id', 'PUT', [
'service' => 'body', // Service comes from the request body
'clientname' => 'body', // Service comes from the request body
]);
To ensure that required parameters are always present, we introduced a function that enforces them for a specific route and request method. This helps maintain data integrity and ensures that our routes receive the necessary input.
Example:
// Require 'service' and 'clientname' to be present in the request body for the PUT method
$router->enforceParameters('/integrations/:id', 'PUT', [
'PUT:body:service,clientname',
]);
With the implementation of a development mode (devmode
), our RESTful Web Service is now endowed with a mode that makes it more streamlined and hassle-free for our developers during the application development phase.
devmode
?devmode
is a feature designed to simplify the development and testing process. When activated, it avoids the need for token-based authentication for each request, making it easier for developers to test different endpoints without having to worry about providing or refreshing authentication tokens. This can significantly speed up development, but it's essential to remember that devmode
should never be activated in production environments, as it bypasses certain security checks.
Get Current DevMode Status
/devmode
devmode
, returning whether it's turned on (true
) or off (false
).GET /devmode
Toggle DevMode
/devmode/toggle
devmode
status. If it's on, it will be turned off and vice versa.GET /devmode/toggle
Set DevMode to a Specific Value
/devmode/toggle/:value
devmode
status to a specific value. The :value
parameter should be replaced with either true
or false
.GET /devmode/toggle/true
or
GET /devmode/toggle/false
devmode
?To check the current status, use the /devmode
endpoint.
To switch the current mode, simply call the /devmode/toggle
endpoint. It will invert the current setting.
To set a specific mode (either true
or false
), use the /devmode/toggle/:value
endpoint, replacing :value
with your desired state.
Important: Always ensure that devmode
is turned off (false
) in production environments for security reasons
The changeUsername
endpoint is responsible for facilitating the process of altering a user's username within the Imperfect Gamers platform. This endpoint is integral to web applications where clients initiate requests to modify usernames.
{
"username": "",
"password": ""
}
The authenticate
function is responsible for authenticating a user. It begins by logging the start of the authentication process and attempts to parse the request body, which should be a JSON string containing the user's credentials (username and password).
The function checks that the required fields (username and password) are present in the request body. It then extracts the username and password and creates a new User object, passing the database connection to the constructor.
It determines whether the provided identifier is an email or a username by calling the appropriate method of the User object. If a password is returned, it indicates the identifier is an email. Otherwise, it assumes it's a username.
If the identifier is neither an email nor a username, the function logs a warning message and sends an error response to the client, indicating that the user was not found.
Next, it verifies the provided password against the password retrieved from the database. If they match, it logs a success message and creates a new Device object, passing the database connection and logger to the constructor.
It then attempts to save the device information in the database and associate the device with the user's login. If successful, it tries to generate and save a token for the user.
If the token is successfully saved, it sends a success response to the client, including the token and the user's ID in the response body. It also logs the successful end of the authentication process.
If any unexpected exceptions occur during the authentication process, the function catches them, logs an error message, and sends an error response to the client.
If the provided password does not match the password in the database, the function logs a failed login attempt and sends an error response to the client, indicating that the provided username or password is invalid.