Project description
In this project, you will create a user table and then use it to register a new user and then allows the user to sign into a website. This project will take 4 weeks.
Watch this video: https://www.youtube.com/watch?v=vrj9AohVhPA
Explanation of the soruce code: video 1, video 2
Please implement the following interface and functoinalty:
- User registration.
- User sign-in, make sure your impelementation is not subject to SQL injection attack.
- search users by first and/or last name.
- search users by userid;
- search all users whose salary is between X and Y.
- Search all users whose ages are between X and Y.
- Search users who registered after john registered, where
john
is the userid. - search users who never signed in.
- Search users who registered on the same day that john registered.
- Return the users who registered today;
Show and explain the results above in a video. Submit all SQL statements in a file called sql.txt.
Consider to create the user table using the following CREATE TABLE stmt (feel free to revise it):
CREATE TABLE Users(
username VARCHAR(50) primary key,
password VARCHAR(50), // maybe encrypted or a hash?
firstname VARCHAR(50),
lastname VARCHAR(50),
salary FLOAT,
age INTEGER,
registerday DATE,
signintime DATETIME
)
Note: the grading will be based on the correct result of the query, the design of the interface and your explnation skill of the results. doenv is a file that you need to customize and rename it to .env to work.
How to run the sample code
- We will use the Apache web server. Create the first webpage index.html under
C:\xampp\htdocs>
(or similar directory where you installed XAMPP) and point your browser to http://localhost/index.html. You should see your first webpage. The purpose of this step is to confirm that the Web server is running, and understand the ROOT URL points to the path location: C:\xampp\htdocs or similar directory in your file system. - At
C:\xampp\htdocs
, rungit clone https://github.com/shiyonglu/database_javascript.git
to copy the whole sample code to the current directory. - Now you can access the Frontend via http://localhost/database_javascript/project1/Frontend/index.html.
- You can configure parameters directly in dbServices.js and app.js. Here, we achieve this by configuring parameters using the .env file. Configure the MySql database according to
C:\xampp\htdocs\database_javascript\project1\Backend\dotenv
, that is, to create a database calledweb_app
and a userjohn
with password1234
via the Admin interfacehttp://localhost/phpmyadmin/
. The userjohn
will be granted with all priviledges for theweb_app
database. To get started, you might also change the dotenv file as follows to only use the root user:
PORT=5050
DB_USER=root
PASSWORD=
DATABASE=web_app
DB_PORT=3306
HOST=localhost
- You need to rename dotenv to .env by command
move dotenv .env
. - Under the database
web_app
, create an empty table as follows:
create table names (id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), date_added DATE);
- Go the Backend directory
C:\xampp\htdocs\database_javascript\project1\Backend
. - npm install express mysql cors nodemon dotenv
- Start the Backend by running
npm start
. - Feel free to access some of the Backend endpoints directly such as http://localhost:5050/getAll. You will only receive JSON data without nice rendering.
- Now you can interact with the Frontend http://localhost/database_javascript/project1/Frontend/index.html.
Finlay, if you need to learn more about nodejs and react: Learn nodejs by examples. Learn react by examples.
Some tips:
- In Mac, to see what process runs on port 5000, type
lsof -i:5000
- In Mac, to kill the process on port 5000, type
kill -9 $(lsof -t -i:5000)
- In Windows, to see what process runs on port 5000, type
netstat -ano | findstr 5000
- In Windows, to kill a process id = 40356, type
taskkill /F /PID 40356
- Mac uses port 5000 for AirPlay already, so you need to disable it if you want to use the same port, see this blog