Skip to content

Commit

Permalink
Merged private changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratstail91 committed Jul 23, 2021
2 parents 9178e89 + d4f9cf3 commit 4298486
Show file tree
Hide file tree
Showing 24 changed files with 45 additions and 60 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git*

tools*
mysql*
letsencrypt*

.env*
2 changes: 1 addition & 1 deletion .envdev
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WEB_PORT=3200
DB_HOSTNAME=database
DB_DATABASE=auth
DB_USERNAME=auth
DB_PASSWORD=venusaur
DB_PASSWORD=charizard

MAIL_SMTP=smtp.example.com
[email protected]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
FROM node:15
WORKDIR "/app"
COPY package*.json ./
RUN npm install --production
COPY . /app
RUN npm install --production
EXPOSE 3200
USER node
ENTRYPOINT ["bash", "-c"]
Expand Down
36 changes: 7 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/admin/ban-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const route = async (req, res) => {
}, {
where: {
username: {
[Op.eq]: req.body.username
[Op.eq]: req.body.username || ''
},
admin: {
[Op.not]: true
Expand All @@ -27,7 +27,7 @@ const route = async (req, res) => {
//forcibly logout
tokens.destroy({
where: {
username: req.body.username
username: req.body.username || ''
}
});

Expand Down
5 changes: 3 additions & 2 deletions server/admin/default-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ module.exports = async () => {
});

if (adminRecord == null) {
const webAddress = process.env.WEB_ADDRESS == 'localhost' ? 'example.com' : process.env.WEB_ADDRESS; //can't log in as "localhost"
await accounts.create({
email: `${process.env.ADMIN_DEFAULT_USERNAME}@${process.env.WEB_ADDRESS}`,
email: `${process.env.ADMIN_DEFAULT_USERNAME}@${webAddress}`,
username: `${process.env.ADMIN_DEFAULT_USERNAME}`,
hash: await bcrypt.hash(`${process.env.ADMIN_DEFAULT_PASSWORD}`, await bcrypt.genSalt(11)),
type: 'normal',
admin: true,
mod: true
});

console.warn(`Created default admin account (email: ${process.env.ADMIN_DEFAULT_USERNAME}@${process.env.WEB_ADDRESS}; password: ${process.env.ADMIN_DEFAULT_PASSWORD})`);
console.warn(`Created default admin account (email: ${process.env.ADMIN_DEFAULT_USERNAME}@${webAddress}; password: ${process.env.ADMIN_DEFAULT_PASSWORD})`);
}
};
2 changes: 1 addition & 1 deletion server/admin/grant-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const route = async (req, res) => {
}, {
where: {
username: {
[Op.eq]: req.body.username
[Op.eq]: req.body.username || ''
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion server/admin/grant-mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const route = async (req, res) => {
}, {
where: {
username: {
[Op.eq]: req.body.username
[Op.eq]: req.body.username || ''
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion server/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ router.use(tokenAuth);
router.use(async (req, res, next) => {
const record = await accounts.findOne({
where: {
username: req.user.username
username: req.user.username || ''
}
});

Expand Down
2 changes: 1 addition & 1 deletion server/admin/remove-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const route = async (req, res) => {
}, {
where: {
username: {
[Op.eq]: req.body.username
[Op.eq]: req.body.username || ''
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion server/admin/remove-mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const route = async (req, res) => {
}, {
where: {
username: {
[Op.eq]: req.body.username
[Op.eq]: req.body.username || ''
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions server/auth/account-delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { accounts } = require('../database/models');
const route = async (req, res) => {
const account = await accounts.findOne({
where: {
id: req.user.id
index: req.user.index
}
});

Expand All @@ -30,7 +30,7 @@ const route = async (req, res) => {
},
{
where: {
id: req.user.id
index: req.user.index
}
});

Expand Down
2 changes: 1 addition & 1 deletion server/auth/account-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { accounts } = require('../database/models');
const route = async (req, res) => {
const account = await accounts.findOne({
where: {
id: req.user.id
index: req.user.index
}
});

Expand Down
2 changes: 1 addition & 1 deletion server/auth/account-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const route = async (req, res) => {
hash: hash
}, {
where: {
id: req.user.id
index: req.user.index
}
});

Expand Down
2 changes: 1 addition & 1 deletion server/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ router.use(tokenAuth);
router.use(async (req, res, next) => {
const record = await accounts.findOne({
where: {
username: req.user.username
username: req.user.username || ''
}
});

Expand Down
6 changes: 3 additions & 3 deletions server/auth/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const route = async (req, res) => {
//get the existing account
const account = await accounts.findOne({
where: {
email: req.body.email
email: req.body.email || ''
}
});

Expand All @@ -38,7 +38,7 @@ const route = async (req, res) => {
//cancel deletion if any
await accounts.update({ deletion: null }, {
where: {
id: account.id
index: account.index
}
});

Expand All @@ -48,7 +48,7 @@ const route = async (req, res) => {
}

//generate the JWT
const tokens = generate(account.id, account.username, account.type, account.admin, account.mod);
const tokens = generate(account.index, account.username, account.type, account.admin, account.mod);

//finally
res.status(200).json(tokens);
Expand Down
2 changes: 1 addition & 1 deletion server/auth/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const validateDetails = async (body) => {
//check for existing username
const usernameRecord = await accounts.findOne({
where: {
username: body.username
username: body.username || ''
}
});

Expand Down
4 changes: 2 additions & 2 deletions server/auth/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const route = async (req, res) => {
//get the existing pending signup
const info = await pendingSignups.findOne({
where: {
username: req.query.username
username: req.query.username || ''
}
});

Expand All @@ -29,7 +29,7 @@ const route = async (req, res) => {
//delete the pending signup
pendingSignups.destroy({
where: {
username: req.query.username
username: req.query.username || ''
}
});

Expand Down
2 changes: 1 addition & 1 deletion server/database/models/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const Sequelize = require('sequelize');
const sequelize = require('..');

module.exports = sequelize.define('accounts', {
id: {
index: {
type: Sequelize.INTEGER(11),
allowNull: false,
autoIncrement: true,
Expand Down
2 changes: 1 addition & 1 deletion server/database/models/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const sequelize = require('..');

module.exports = sequelize.define('tokens', {
token: 'varchar(320)',
username: 'varchar(320)'
username: 'varchar(320)' //TODO: why username?
});
3 changes: 1 addition & 2 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ require('dotenv').config();
const express = require('express');
const app = express();
const server = require('http').Server(app);
const bodyParser = require('body-parser');
const cors = require('cors');

//config
app.use(bodyParser.json());
app.use(express.json());
app.use(cors());

//database connection
Expand Down
4 changes: 2 additions & 2 deletions server/utilities/token-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const jwt = require('jsonwebtoken');
const { tokens } = require('../database/models');

//generates a JWT token based on the given arguments
module.exports = (id, username, type, admin, mod) => {
module.exports = (index, username, type, admin, mod) => {
const content = {
id,
index,
username,
type,
admin,
Expand Down
2 changes: 1 addition & 1 deletion server/utilities/token-refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = (token, callback) => {
return callback(403);
}

const result = generate(user.id, user.username, user.type, user.admin, user.mod);
const result = generate(user.index, user.username, user.type, user.admin, user.mod);

destroy(token);

Expand Down
4 changes: 2 additions & 2 deletions server/utilities/validate-username.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ module.exports = username => {
if (username.length < 8 && username.length > 100) {
return false;
}

if (!isAlpha(username)) {
return false;
}

return true;
}

Expand Down

0 comments on commit 4298486

Please sign in to comment.