diff --git a/scripts/database/entry/activity.JS b/scripts/database/entry/activity.JS new file mode 100644 index 0000000..477a6dd --- /dev/null +++ b/scripts/database/entry/activity.JS @@ -0,0 +1,14 @@ +const Entry = require(`./object.JS`); + +class Activity extends Entry { + username; + description; + duration; + date; + + constructor(PROPERTIES) { + super(PROPERTIES); + }; +} + +module.exports = Activity; \ No newline at end of file diff --git a/scripts/database/entry/object.JS b/scripts/database/entry/object.JS new file mode 100644 index 0000000..6b2169b --- /dev/null +++ b/scripts/database/entry/object.JS @@ -0,0 +1,10 @@ +/* An object to represent an entry in the database. */ +class Entry { + constructor(PROPERTIES) { + (PROPERTIES) ? Object.entries(PROPERTIES).forEach(([property, value]) => { + this[property] = value; + }) : false; + }; +}; + +module.exports = Entry; \ No newline at end of file diff --git a/scripts/database/entry/user.JS b/scripts/database/entry/user.JS new file mode 100644 index 0000000..899078e --- /dev/null +++ b/scripts/database/entry/user.JS @@ -0,0 +1,55 @@ +const Entry = require(`./object`); +const Hash = require(`../../utilities/hash`); + +class User extends Entry { + // Default properties + name; + ID; + activated = false; + passcode; + #login = false; + + constructor(PROPERTIES) { + super(PROPERTIES); + this.authenticate(); + }; + + /* Authenticate the user + + @param {STRING} INPUT the passcode passed + @return {BOOLEAN} the user authentication state + */ + authenticate(INPUT) { + // Reset the login state. + if (this.#login) {this.#login = false;}; + + if ((this.passcode) ? (INPUT && this.passcode == INPUT) : true) { + this.#login = true; + } + return (this.#login); + } + + /* + Generate a schema for MongoDB. + + @return {OBJECT} the schema + */ + static generateTemplate() { + let SCHEMA = { + "name": {"type": String, "required": true, "unique": true, "dropDups": true}, + "ID": {"type": String, "required": true, "unique": true, "dropDups": true}, + "activated": {"type": Boolean}, + "passcode": {"type": String} + } + let TEST = new User(); + + // Verify that the schema is valid. + Object.keys(SCHEMA).forEach((KEY) => { + if (!Object.keys(TEST).includes(KEY)) {delete SCHEMA[KEY];}; + }); + + return (SCHEMA) + } +} + +module.exports = User; \ No newline at end of file