From 80930dac4f1400e68276d03246a8ee331301f200 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Sun, 5 Jul 2020 16:43:12 -0500 Subject: [PATCH] =?UTF-8?q?Ready=20for=20release=3F=20=F0=9F=A4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/models/user.model.ts | 10 +- src/app/routes/auth.ts | 12 ++- src/app/routes/routes.ts | 26 ++++- src/app/views/configs.ejs | 100 ++++++++++++++++++ src/app/views/home.ejs | 25 +++-- src/app/views/login.ejs | 41 +++++++- src/app/views/register.ejs | 107 ++++++++++++++++++++ src/public/assets/css/base.css | 2 +- src/public/assets/js/configs.js | 39 +++++++ src/public/assets/js/modules/init.module.js | 4 + src/public/assets/js/register.js | 76 ++++++++++++++ 11 files changed, 410 insertions(+), 32 deletions(-) create mode 100644 src/app/views/configs.ejs create mode 100644 src/app/views/register.ejs create mode 100644 src/public/assets/js/configs.js create mode 100644 src/public/assets/js/register.js diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index 55e55bc..7f85dde 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -5,8 +5,7 @@ const UserSchema = new Schema({ username: String, password: String, configs: [{ - name: String, - conf: String + type: String }] }) @@ -24,15 +23,10 @@ UserSchema.methods.changePassword = function (password: string, newPassword: str } } -interface INamedConfig { - name: string, - conf: string -} - export type UserModel = Document & { username: string, password: string, - configs: Array, + configs: Array, generateHash: Function, validPassword: Function, changePassword: Function diff --git a/src/app/routes/auth.ts b/src/app/routes/auth.ts index 0c92cc0..f4c9391 100644 --- a/src/app/routes/auth.ts +++ b/src/app/routes/auth.ts @@ -30,8 +30,14 @@ export const init = (app: Application, passport: PassportStatic) => { } }) + app.get('/register', async (req, res) => { + res.render('register') + }) + app.post('/register', async (req, res) => { - const exUser = await UserDB.findOne({ 'email': req.body.email }) + const exUser = await UserDB.findOne({ + 'username': req.body.username + }) if (exUser) { res.redirect('/register?exists') } else { @@ -40,6 +46,10 @@ export const init = (app: Application, passport: PassportStatic) => { user.password = user.generateHash(req.body.password) user.configs = Array() await user.save() + + req.logIn(user, () => { + res.redirect('/') + }) } }) } \ No newline at end of file diff --git a/src/app/routes/routes.ts b/src/app/routes/routes.ts index 335262c..5e1f183 100644 --- a/src/app/routes/routes.ts +++ b/src/app/routes/routes.ts @@ -19,10 +19,10 @@ export const init = (app: Application, passport: PassportStatic) => { await conf.save() if (req.isAuthenticated() && req.user) { - req.user.configs.push({ - name: req.body.name, - conf: conf.shortid - }) + req.user.configs.push( + conf.shortid + ) + await req.user.save() } res.status(200).send(conf) } catch (ex) { @@ -32,6 +32,24 @@ export const init = (app: Application, passport: PassportStatic) => { } }) + app.get('/configs', async (req, res) => { + if (req.isAuthenticated() && req.user) { + res.render('configs', { + user: req.user + }) + } else { + res.redirect('/login?origin=/configs') + } + }) + + app.post('/configs', async (req, res) => { + if (req.isAuthenticated() && req.user) { + res.json(req.user.configs) + } else { + res.json([]) + } + }) + app.get('/configs/:id', async (req, res) => { const conf = await ConfigDB.findOne({ shortid: req.params.id diff --git a/src/app/views/configs.ejs b/src/app/views/configs.ejs new file mode 100644 index 0000000..17e089a --- /dev/null +++ b/src/app/views/configs.ejs @@ -0,0 +1,100 @@ + + + + + + + Geolosys Configurator + + + + + + + + + + + + + + +
+ +

Your Geolosys Configs

+
+ +
+ + + + + + + + + +
#Config
+
+ + + + + \ No newline at end of file diff --git a/src/app/views/home.ejs b/src/app/views/home.ejs index 673ea45..d927545 100644 --- a/src/app/views/home.ejs +++ b/src/app/views/home.ejs @@ -39,7 +39,7 @@