Emergency Alert Application
Documentation
Table of Contents
Introduction
This is an application for Estonian Wildlife Center to manage alerts made by member of the public about injured animals. The applications main purpose is to provide a platform for the public to report injured animals and for the center's volunteers to manage these alerts. Additionally, the application provides the following features:
- A ticketing system for managing alerts
- A knowledge base for common injuries and how to handle them
- A user management system for managing users and roles
- A statistics page for viewing the number of alerts and their status
- An applications management system for managing the new applications
- A settings page for managing the application settings like tags and functions
Features
- Ticketing system
- Knowledge base
- User management
- Statistics
- Applications management
- Settings
- Profile
Running the application
Backend
- Clone the repository
- Create a database named 'EAA' to your database server (e.g. PgAdmin)
- Open the project in your IDE
- Set database variables to your environment variables (see application.properties)
- Set jwt secret to your environment variables (see SecurityConfig.java)
The following code can be used to generate a jwt secret for your variable.
import java.security.SecureRandom;
import java.util.Base64;
public class GenerateJWTSecret {
public static void main(String[] args) {
SecureRandom random = new SecureRandom();
byte[] key = new byte[64]; // 512 bits
random.nextBytes(key);
String jwtSecret = Base64.getEncoder().encodeToString(key);
System.out.println("Generated JWT Secret: " + jwtSecret);
}
}
- Run the application
- The application will run on port 8080
Frontend
- Move to the frontend directory
- Run
npm install
- Run
npm run serve
- The frontend will run on port 8081
In order to test different roles and see the permitted views of each user role you can test with the following users (log in with the following credentials):
NB! Password for all is "password123"
You are able to see their role in the profile page.
Running on Docker is also available. There are Dockerfiles and docke-compose file made specially for that.
There is also a .jar file available in the root folder.
Contributing
The following members contributed to this project:
License
This project is owned by the Estonian Wildlife Center.
Documentation
Description of the general workflow:
- The user opens the application and is on a welcome page that describes the organization.
What the user can do without logging in:
- The user can navigate to the alert page to report an injured animal.
- The user can navigate to the registration page to create an application to become a volunteer.
- The user can navigate to the login page and insert their email and password to log in.
What happens when user logs in:
- The server create a token for them, which they can use to access the main application and its features.
- The token will expire after 1 hour.
- If the token is expired the frontend should redirect the user to the login page. This can be done by checking the backend's response and handling un-authorization with logging out.
- If the un-authorization is not handled, the user will be stuck in the application without the ability to access any features and probably error messages.
- If the token is not expired the user should be logged in after refreshing the page and even when closing the application and reopening within an hour.
What the user can do after logging in:
- The user can navigate between the different pages of the application defined in the navigation bar. (the pages depend on the uer role = rights)
- The user can go to their own profile.
- The user can log out.
Backend
Entities
These are the entities used in the application. They are used to represent the database tables.
- Users are connected to roles, regions, species and tags.
- Tickets are connected to users, species and posts
- Applications are connected to tags.
- Species are connected to upper species and tickets.
Repositories
These are the repositories used in the application. They are used to interact with the database.
Services
These are the services used in the application. They are used to interact with the repositories and perform business logic.
Controllers
These are the controllers used in the application. They are used to handle the HTTP requests.
DTOs
These are the DTOs used in the application. They are used to transfer data between the frontend and the backend.
Components
There is a component for data initialization. It is used to initialize the database with some data. The data is initialized in a table, in case the table is empty. If you do any changes to the data, you need to delete the data in the table and restart the application IN CASE you wish the table to have the exact data which is defined in the initialization component.
Security
These are the classes used for security in the application. They are used to authenticate and authorize users.
- SecurityConfig is used to configure the security settings. It uses JWT for authentication. All requests are authenticated except for the login and register requests.
- JwtAuthorizationFilter is used to filter the requests and validate the JWT token.
- CustomAuthenticationFilter is used to authenticate the user.
NB! This is important information that should be read before starting to work on the project:
- Currently only login is accessible without authentication. To access other endpoints, you need to be authenticated.
- To authenticate, you need to send a POST request to /login with the following body (this is done in the login method in the frontend):
{
"email": "...",
"password": "..."
}
- The response will contain a JWT token that you need to include in the Authorization header of your requests (the token is stored in the frontend store):
{
'Authorization': `Bearer ${this.token}`
}
- The token is valid for 1 hour. After that, you need to authenticate again.
- No endpoints are accessible without authentication. If you try to access an endpoint without authentication, you will get a 403 Forbidden response.
- The backend endpoints can be constructed normally, just remember to include the Authorization header with the token when you make an API call in the frontend.
Frontend
Components
These are the components used in the application. They are used to display the data and handle the user input.
Pages
These are the pages used in the application. They are used to display the components. They will perform most of the logic. Please include the JWT token in the Authorization header when making requests to the backend.
Routes
These are the routes used in the application. They are used to navigate between the pages.
Store
This is the store used in the application. It is used to store the data and manage the state of the application. Currently, the logged-in user's data is stored in the store.