Implemented default admin account

This commit is contained in:
2021-02-11 13:18:18 +11:00
parent 01f17360b9
commit 7759a1cd40
7 changed files with 36 additions and 34 deletions
+6
View File
@@ -57,6 +57,7 @@ There are external components to this template referred to as "microservices". T
- ~~logout (with cookies)~~ - ~~logout (with cookies)~~
- ~~account deletion~~ - ~~account deletion~~
- Administration Panel - Administration Panel
- ~~Default admin account~~
- ~~Exclusive to admin accounts~~ - ~~Exclusive to admin accounts~~
- inspect aggregate user data - inspect aggregate user data
- ~~News blog system (microservice)~~ - ~~News blog system (microservice)~~
@@ -72,7 +73,12 @@ There are external components to this template referred to as "microservices". T
- Configuraton Script: - Configuraton Script:
- Default UUID keys - Default UUID keys
- ~~Docker, docker, docker.~~ - ~~Docker, docker, docker.~~
- Better compression for client files
- Full tutorial for setting up and using the site
- Start here page - Start here page
- Security holes
- HTTPS
- Default admin account
# Email settings # Email settings
+1 -19
View File
@@ -49,15 +49,10 @@ const LogIn = props => {
); );
}; };
//DOCS: returns two values: response and OK
const handleSubmit = async (email, password) => { const handleSubmit = async (email, password) => {
email = email.trim(); email = email.trim();
const err = handleValidation(email, password);
if (err) {
return err;
}
//generate a new formdata payload //generate a new formdata payload
let formData = new FormData(); let formData = new FormData();
@@ -73,17 +68,4 @@ const handleSubmit = async (email, password) => {
} }
}; };
//returns an error message, or null on success
const handleValidation = (email, password) => {
if (!validateEmail(email)) {
return 'invalid email';
}
if (password.length < 8) {
return 'invalid password (Must be at least 8 characters long)';
}
return null;
};
export default LogIn; export default LogIn;
-2
View File
@@ -151,7 +151,6 @@ networks:
const dockerfile = ` const dockerfile = `
FROM node:15 FROM node:15
WORKDIR "/app" WORKDIR "/app"
WORKDIR "/app"
COPY package*.json ./ COPY package*.json ./
RUN npm install RUN npm install
RUN apt-get update RUN apt-get update
@@ -159,7 +158,6 @@ RUN apt-get install -y mariadb-client
COPY . /app COPY . /app
EXPOSE 3000 EXPOSE 3000
ENTRYPOINT ["bash", "-c"] ENTRYPOINT ["bash", "-c"]
CMD ["mysql --host=database --user=root --password=${databaseRootPassword} < ./startup.sql && npm start"] CMD ["mysql --host=database --user=root --password=${databaseRootPassword} < ./startup.sql && npm start"]
`; `;
+2 -2
View File
@@ -56,8 +56,8 @@ const route = async (req, res) => {
}; };
const validateDetails = async (fields) => { const validateDetails = async (fields) => {
//basic formatting //basic formatting (with an exception for the default admin account)
if (!validateEmail(fields.email)) { if (!validateEmail(fields.email) && fields.email != `admin@${process.env.WEB_ADDRESS}`) {
return 'invalid email'; return 'invalid email';
} }
+23
View File
@@ -16,4 +16,27 @@ router.get('/banned', require('./banned'));
router.post('/ban', require('./ban')); router.post('/ban', require('./ban'));
router.post('/unban', require('./unban')); router.post('/unban', require('./unban'));
//DOCS: ensure that there is at least one administration account
const bcrypt = require('bcryptjs');
const { accounts } = require('../database/models');
(async () => {
const admin = await accounts.findOne({
where: {
privilege: 'administrator'
}
});
if (admin == null) {
await accounts.create({
privilege: 'administrator',
email: `admin@${process.env.WEB_ADDRESS}`,
username: `admin`,
hash: await bcrypt.hash('password', await bcrypt.genSalt(11))
});
console.log(`Created default admin account (email: admin@${process.env.WEB_ADDRESS}; password: password)`);
}
})();
module.exports = router; module.exports = router;
-10
View File
@@ -1,10 +0,0 @@
#This file only needs to be run once, during initial setup
#After this script, next run 'update_database.sql'
#Create the actual database
CREATE DATABASE IF NOT EXISTS template;
USE template;
#Create the database user
CREATE USER IF NOT EXISTS 'template'@'%' IDENTIFIED BY 'pikachu';
GRANT ALL PRIVILEGES ON template.* TO 'template'@'%';
+3
View File
@@ -1,3 +1,6 @@
# Do not use this file - this is just a guide for my own use
# account system # account system
CREATE TABLE IF NOT EXISTS pendingSignups ( CREATE TABLE IF NOT EXISTS pendingSignups (
email VARCHAR(320) UNIQUE, email VARCHAR(320) UNIQUE,