Skip to content

Commit

Permalink
Update 1.3.0
Browse files Browse the repository at this point in the history
* Update 1.3.0

- Move settings storage/configuration to MongoDB.
- Rename settings.json to default-settings.json to better suit its new purpose.
- Cleanup of old code.
- Made formatting a bit more consistent between files.

Commit from P. Roy

* Quick fix to settings model

* Fix personnel list footer not being fixed to the bottom

* Small additions

- Major update deserves a major version revision ;) [changed to 1.3.0]
- Minor changes to default settings
- When there are many users on listusers.ejs, not having it fixed will actually look better since the footer wont hover over the long list while scrolling. [Reverted back]
- Small change in wording in settings.ejs

Co-authored-by: Red-Thirten <[email protected]>
  • Loading branch information
peter-r-g and redthirten authored May 23, 2020
1 parent e7805b4 commit 5c05c5d
Show file tree
Hide file tree
Showing 13 changed files with 709 additions and 421 deletions.
74 changes: 44 additions & 30 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const express = require("express"),
mongoose = require("mongoose"),
passport = require("passport"),
LocalStrategy = require("passport-local"),
User = require("./models/user"),
authRoutes = require("./routes/index"),
listUsersRoutes = require("./routes/listusers"),
opCenterRoutes = require("./routes/opcenter"),
Expand All @@ -15,7 +14,7 @@ const express = require("express"),
cookieParser = require("cookie-parser"),
favicon = require('serve-favicon'),
path = require('path'),
config = require('./settings.json');
Config = require("./models/settings");

const NODE_PORT = process.env.NODE_PORT || 3000;
const MONGO_IP = process.env.MONGO_IP || 'localhost';
Expand All @@ -31,37 +30,52 @@ app.use(favicon(path.join(__dirname, '.', 'public', 'favicon.ico')));

//PASSPORT
app.use(require("express-session")({
secret: "Motta sucks",
resave: false,
saveUninitialized: false
secret: "Motta sucks",
resave: false,
saveUninitialized: false
}));

app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());
Config.find({}, function(err, result) {
if (err) throw err;

var config;
if (result.length == 0) {
var DefaultConfig = new Config();
DefaultConfig.save();

app.use(function(req, res, next){
res.locals.config = config;
res.locals.currentUser = req.user;
res.locals.success = req.flash('success');
res.locals.error = req.flash('error');
next();
});
config = DefaultConfig;
} else
config = result[0];

app.use(authRoutes);
app.use(listUsersRoutes);
app.use(opCenterRoutes);
app.use(userRoutes);
app.use(calendarRoutes);
let User = require("./models/user")(config);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404).render('404');
});
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(User.authenticate()));
passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

app.use(function(req, res, next){
res.locals.config = config;
res.locals.currentUser = req.user;
res.locals.success = req.flash('success');
res.locals.error = req.flash('error');
next();
});

app.listen(NODE_PORT, function(){
console.log("PERSMAN: ONLINE") ;
});
app.use(authRoutes);
app.use(listUsersRoutes);
app.use(opCenterRoutes);
app.use(userRoutes);
app.use(calendarRoutes);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
res.status(404).render('404');
});

app.listen(NODE_PORT, function(){
console.log("PERSMAN: ONLINE") ;
});
});
160 changes: 160 additions & 0 deletions default-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"websiteName":"10th Mountain Division",
"websiteSubtitle":"Arma 3 Milsim Unit",
"landingText":"<center>\r\n<h2>About Us</h2>\r\n<br>\r\n<h5>Designated as a mountain warfare unit, this mil-sim unit specializes in combat for Alpine-like conditions. Dedicated to quality and teamwork, we hope prospective members will be interested in our direct-action activities across a variety of missions.</h5>\r\n<br>\r\n<h2>Biography</h2>\r\n<br>\r\n10th Mountain Division is a unit that was created by a member base that has been doing ArmA 3 mil-sim for upwards of 5 years. We've decided to establish ourselves as a unit in order to find other like minded people to become members of our active and tight-knit community. We're modeled off the United States Army 22nd Infantry Regiment and will be conducting operations that are comparable to our real-life counterpart. As a semi-fictional unit, we'll have the flexibility to participate in operations that are on going in the real-world, explore \"what-if\" scenarios, or create our own. \r\n<br><br>\r\nIf this sounds like something you're interested in and want to become a part of, submit an application and PLEASE JOIN either our <a href=\"https://discord.gg/zPmUpYU\" target=\"_blank\">Discord</a> or <a href=\"ts3server://ts.10thmtn.org\" target=\"_blank\">TeamSpeak</a> servers to find more information and to meet our members.\r\n<br><br>\r\n<h2>Climb to Glory!</h2>\r\n<br>\r\n<img src=\"/images/10th_logo_motto.png\">\r\n</center>",
"faq":"",
"resourceLinks":[
"https://docs.google.com/document/d/1m9pg61-rfC3yhndQZUIZAO7laRFHQlV82tQSg4j4OCw/edit?usp=sharing",
"https://docs.google.com/document/d/11DgFRLRKKL6cJNK99ru7hTNPqv4pafoo7uqs7gUDK1A/edit?usp=sharing"
],
"resourceTitles":[
"Student SOP Manual",
"Community Guidelines"
],
"mailerEmail":"",
"mailerPassword":"",
"websiteLogo":"/images/10th_logo.png",
"carouselImages":[
"/images/banner1.jpg",
"/images/banner2.jpg",
"/images/banner3.jpg",
"/images/banner4.jpg",
"/images/banner5.jpg",
"/images/banner6.jpg",
"/images/banner7.jpg",
"/images/banner8.jpg"
],
"carouselTitles":[
"Arma 3 Milsim Mountain Warfare Unit",
"With 50+ members and growing our comunity continues to stay active and diverse.",
"Never a dull moment - Operations every Sunday and exercises throughout the week.",
"Friendly staff are always able and willing to support all player skill levels.",
"Join exciting/action packed missions that mix story and tactics for an immersive experience.",
"Climb to glory as 10th MTN will conquer any challenging terrain or environment.",
"Grow camaraderie and effective combat strategies with our well-trained members.",
"We look forward to seeing you on the battlefield! Enlist today to join a member base that has been doing ArmA 3 milsim for upwards of 5 years!"
],
"modlistURL":"https://steamcommunity.com/sharedfiles/filedetails/?id=1975625031",
"a3unitsURL":"https://units.arma3.com/unit/10thmtn",
"steamgroupURL":"https://steamcommunity.com/groups/10thmtndivision",
"donateURL":"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RK8Y7WRHQTRL4&source=url",
"ts3URL":"ts.10thmtn.org",
"discordURL":"https://discordapp.com/invite/8BBDHMz",
"youtubeURL":"",
"instagramURL":"https://www.instagram.com/10thmtnarma/",
"enableApplication":"on",
"enableCallToAction":"on",
"enableRetiredMembers":"on",
"companies":[
"Anvil"
],
"platoons":[
"Company HQ",
"2-10th Aviation Regiment",
"1st Platoon",
"2nd Platoon",
"Training Platoon",
"None"
],
"squads":[
"Headquarters",
"1st Squad",
"2nd Squad",
"3rd Squad",
"4th Squad",
"Training",
"None"
],
"teams":[
"Leadership",
"Alpha",
"Bravo",
"None"
],
"sShops":[
"S-1",
"S-2",
"S-3",
"S-4",
"S-5"
],
"ranks":[
"None",
"RCT",
"PVT",
"PV2",
"PFC",
"SPC",
"CPL",
"SGT",
"SSG",
"SFC",
"MSG",
"1SG",
"SGM",
"CSM",
"WOC",
"WO1",
"CW2",
"CW3",
"CW4",
"CW5",
"2LT",
"1LT",
"CPT"
],
"roles":[
"Rifleman",
"Auto-Rifleman",
"Team Leader",
"Squad Leader",
"Platoon Sergeant",
"Platoon Leader",
"Company Leader",
"Game Master",
"Radio Operator",
"Pilot",
"Medic",
"None"
],
"tabs":[
"Mountain",
"Ranger",
"Airborne"
],
"tabDesc":[
"This tab is unique to the 10th MTN Div. and certifies that the wearer is qualified to traverse and navigate challenging mountainous and Alpine terrain.",
"Ranger School is one of the toughest training courses for which a Soldier can volunteer. Army Rangers are experts in leading Soldiers on difficult missions - and to do this they require rigorous training.",
"The purpose of the Airborne Tab is to qualify the volunteer in the use of the parachute as a means of combat deployment."
],
"certifications":[
"Basic Combat Training",
"Airborne School",
"Pathfinder School",
"Air Assault School",
"Ranger School",
"Heavy AT Qualified",
"Advanced Explosives Qualified",
"Grenade Launcher Qualified",
"Combat Lifesaver",
"Basic Leader Course",
"Advanced Leader Course",
"RTO School",
"Designated Marksman"
],
"awards":[
"Operation - Unstable Ground"
],
"awardDesc":[
"Participated in 70% or more of Operation: Unstable Ground"
],
"userGroups":[
"Guest",
"Enlisted",
"Instructor",
"Recruiter",
"Officer",
"Site Admin"
],
"enableVisibility":"on"
}
43 changes: 43 additions & 0 deletions models/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const mongoose = require("mongoose"),
config = require("../default-settings.json");

const SettingsSchema = new mongoose.Schema({
websiteName: {type: String, default: config.websiteName},
websiteSubtitle: {type: String, default: config.websiteSubtitle},
landingText: {type: String, default: config.landingText},
faq: {type: String, default: config.faq},
resourceLinks: {type: Array, default: config.resourceLinks},
resourceTitles: {type: Array, default: config.resourceTitles},
mailerEmail: {type: String, default: config.mailerEmail},
mailerPassword: {type: String, default: config.mailerPassword},
websiteLogo: {type: String, default: config.websiteLogo},
carouselImages: {type: Array, default: config.carouselImages},
carouselTitles: {type: Array, default: config.carouselTitles},
modlistURL: {type: String, default: config.modlistURL},
a3unitsURL: {type: String, default: config.a3unitsURL},
steamgroupURL: {type: String, default: config.steamgroupURL},
donateURL: {type: String, default: config.donateURL},
ts3URL: {type: String, default: config.ts3URL},
discordURL: {type: String, default: config.discordURL},
youtubeURL: {type: String, default: config.youtubeURL},
instagramURL: {type: String, default: config.instagramURL},
enableApplication: {type: String, default: config.enableApplication},
enableCallToAction: {type: String, default: config.enableCallToAction},
enableRetiredMembers: {type: String, default: config.enableRetiredMembers},
companies: {type: Array, default: config.companies},
platoons: {type: Array, default: config.platoons},
squads: {type: Array, default: config.squads},
teams: {type: Array, default: config.teams},
sShops: {type: Array, default: config.sShops},
ranks: {type: Array, default: config.ranks},
roles: {type: Array, default: config.roles},
tabs: {type: Array, default: config.tabs},
tabDesc: {type: Array, default: config.tabDesc},
certifications: {type: Array, default: config.certifications},
awards: {type: Array, default: config.awards},
awardDesc: {type: Array, default: config.awardDesc},
userGroups: {type: Array, default: config.userGroups},
enableVisibility: {type: String, default: config.enableVisibility}
});

module.exports = mongoose.model("Settings", SettingsSchema);
69 changes: 39 additions & 30 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
const mongoose = require("mongoose"),
passportLocalMongoose = require("passport-local-mongoose"),
uniqueValidator = require('mongoose-unique-validator'),
config = require('../settings.json');
var UserModelInstance = undefined;

const UserSchema = new mongoose.Schema({
email: {type: String, unique: true, required: [true, "Email can't be blank."], match: [/\S+@\S+\.\S+/, 'Email is invalid.']},
username: {type: String, unique: true, required: true},
displayname: {type: String, unique: true, required: [true, "Display name can't be blank."]},
password: String,
registrationDate: Date,
steamProfile: String,
discordUsername: String,
country: String,
age: Number,
certifications: Array,
tabs: Array,
awards: Array,
preferredTheme: {type: String, default: "Dark"},
unit: {type: Object, default: {company: "none", platoon: "none", squad: "none", team: "none"}},
status: {type: String, default: "None"},
rank: {type: String, default: "None"},
position: {type: String, default: "None"},
sShops: Array,
role: {type: Object, default: {name: config.userGroups[0], num: 0}},
resetPasswordToken: String,
resetPasswordExpires: Date,
});
module.exports = function(config) {
if (UserModelInstance !== undefined)
return UserModelInstance;

if (!config) throw "Didn't receive config!";

const mongoose = require("mongoose"),
passportLocalMongoose = require("passport-local-mongoose"),
uniqueValidator = require('mongoose-unique-validator');

UserSchema.plugin(passportLocalMongoose);
UserSchema.plugin(uniqueValidator, {message: 'A user with the given {PATH} of {VALUE} already exists.'});
const UserSchema = new mongoose.Schema({
email: {type: String, unique: true, required: [true, "Email can't be blank."], match: [/\S+@\S+\.\S+/, 'Email is invalid.']},
username: {type: String, unique: true, required: true},
displayname: {type: String, unique: true, required: [true, "Display name can't be blank."]},
password: String,
registrationDate: Date,
steamProfile: String,
discordUsername: String,
country: String,
age: Number,
certifications: Array,
tabs: Array,
awards: Array,
preferredTheme: {type: String, default: "Dark"},
unit: {type: Object, default: {company: "none", platoon: "none", squad: "none", team: "none"}},
status: {type: String, default: "None"},
rank: {type: String, default: "None"},
position: {type: String, default: "None"},
sShops: Array,
role: {type: Object, default: {name: config.userGroups[0], num: 0}},
resetPasswordToken: String,
resetPasswordExpires: Date,
});

module.exports = mongoose.model("User", UserSchema);
UserSchema.plugin(passportLocalMongoose);
UserSchema.plugin(uniqueValidator, {message: 'A user with the given {PATH} of {VALUE} already exists.'});

UserModelInstance = mongoose.model("User", UserSchema)
return UserModelInstance;
}
Loading

0 comments on commit 5c05c5d

Please sign in to comment.