Browse Source

fixed routing for non-admin users

lllllllillllllillll 1 year ago
parent
commit
b22894f366
4 changed files with 149 additions and 19 deletions
  1. 6 2
      controllers/login.js
  2. 2 2
      router/index.js
  3. 30 0
      views/apps.ejs
  4. 111 15
      views/portal.ejs

+ 6 - 2
controllers/login.js

@@ -41,8 +41,12 @@ export const submitLogin = async function(req,res){
                     ip: req.socket.remoteAddress
                 });
 
-
-                res.redirect("/");
+                if (req.session.role == "admin") {
+                    res.redirect("/");
+                }
+                else {
+                    res.redirect("/portal");
+                }
             }else{
 
                 const syslog = await Syslog.create({

+ 2 - 2
router/index.js

@@ -26,7 +26,7 @@ const auth = (req, res, next) => {
     if (req.session.role == "admin") {
         next();
     } else {
-        res.redirect("/portal");
+        res.redirect("/login");
     }
 };
 
@@ -39,7 +39,7 @@ router.post("/register", submitRegister);
 router.get("/", auth, Dashboard);
 router.post("/", auth, searchDashboard);
 
-router.get("/portal", auth, Portal)
+router.get("/portal", Portal)
 
 router.get("/apps", auth, Apps);
 router.get("/apps/:page", auth, Apps);

+ 30 - 0
views/apps.ejs

@@ -45,6 +45,12 @@
                   </form>
                   <input type="submit" form="search" class="btn btn-outline-success h-50" value="search">
 
+
+                  <form action="/apps" id="search2" name="search2" method="POST">
+                    <input type="search" class="form-control" name="search2" placeholder="Search apps…">
+                  </form>
+                  <input type="submit" form="search2" class="btn btn-outline-success h-50" value="search2">
+
                   <div class="card-actions btn-actions">
                     <div class="card-actions btn-actions">
                       <div class="dropdown">
@@ -107,5 +113,29 @@
     <!-- Tabler Core -->
     <script src="js/tabler.min.js" defer></script>
     <script src="js/demo.min.js" defer></script>
+    <script>
+
+      const form = document.querySelector("#userinfo");
+
+      async function sendData() {
+        const formData = new FormData(form);
+
+        try {
+          const response = await fetch("/install", {
+            method: "POST",
+            body: formData,
+          });
+          console.log(await response.json());
+        } catch (e) {
+          console.error(e);
+        }
+      }
+
+      form.addEventListener("submit", (event) => {
+        event.preventDefault();
+        sendData();
+      });
+
+    </script>
   </body>
 </html>

+ 111 - 15
views/portal.ejs

@@ -19,26 +19,122 @@
     </style>
   </head>
   <body >
-  <div class="page">
+    <div class="page">
 
-    <%- include('navbar.ejs') %>
-    <div class="page-wrapper">
-
-      <div class="page-body">
-        <div class="container-xl">
-          <div class="row row-deck row-cards">
-            
-            
-            
-            
+      <%- include('navbar.ejs') %>
+      <div class="page-wrapper">
+  
+        <div class="page-body">
+          <div class="container-xl">
+            <div class="row row-deck row-cards">
+              
+              <div class="col-12" id="cards">
+                <div class="row row-cards">
+                  
+                  <div class="col-sm-6 col-lg-3">
+                    <div class="card card-sm">
+                      <div class="card-body">
+                        <div class="row align-items-center">
+                          <div class="col-auto">
+                            <span class="bg-primary text-white avatar">
+                              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-cpu" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M5 5m0 1a1 1 0 0 1 1 -1h12a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-12a1 1 0 0 1 -1 -1z"></path><path d="M9 9h6v6h-6z"></path><path d="M3 10h2"></path><path d="M3 14h2"></path><path d="M10 3v2"></path><path d="M14 3v2"></path><path d="M21 10h-2"></path><path d="M21 14h-2"></path><path d="M14 21v-2"></path><path d="M10 21v-2"></path></svg>
+                            </span>
+                          </div>
+                          <div class="col">
+                            <div class="font-weight-medium">
+                              <label id="cpu-text" class="cpu-text mb-1" for="cpu">I had to put something here.</label>
+                            </div>
+                            <div id="cpu-bar" class="cpu-bar meter animate">
+                              <span style="width: 25%"><span></span></span>
+                            </div>
+                          </div>
+                        </div>
+                      </div>
+                    </div>
+                  </div>
+  
+                  <div class="col-sm-6 col-lg-3">
+                    <div class="card card-sm">
+                      <div class="card-body">
+                        <div class="row align-items-center">
+                          <div class="col-auto">
+                            <span class="bg-green text-white avatar">
+                              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-container" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M20 4v.01"></path> <path d="M20 20v.01"></path> <path d="M20 16v.01"></path> <path d="M20 12v.01"></path> <path d="M20 8v.01"></path> <path d="M8 4m0 1a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1v14a1 1 0 0 1 -1 1h-6a1 1 0 0 1 -1 -1z"></path> <path d="M4 4v.01"></path> <path d="M4 20v.01"></path> <path d="M4 16v.01"></path> <path d="M4 12v.01"></path> <path d="M4 8v.01"></path> </svg>                            
+                            </span>
+                          </div>
+                          <div class="col">
+                            <div class="font-weight-medium">
+                              <label id="ram-text" class="ram-text mb-1" for="ram">RAM 0%</label>
+                            </div>
+                            <div id="ram-bar" class="ram-bar meter animate orange">
+                              <span style="width: 25%"><span></span></span>
+                            </div>
+                          </div>
+                        </div>
+                      </div>
+                    </div>
+                  </div>
+                  
+                  <div class="col-sm-6 col-lg-3">
+                    <div class="card card-sm">
+                      <div class="card-body">
+                        <div class="row align-items-center">
+                          <div class="col-auto">
+                            <span class="bg-twitter text-white avatar">
+                              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-arrows-left-right" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M21 17l-18 0"></path> <path d="M6 10l-3 -3l3 -3"></path> <path d="M3 7l18 0"></path> <path d="M18 20l3 -3l-3 -3"></path> </svg>                            
+                            </span>
+                          </div>
+                          <div class="col">
+                            <div class="font-weight-medium">
+                              <label id="net-text" class="net-text mb-1" for="network">Down: 0MB  Up: 0MB</label>
+                            </div>
+                            <div id="net-bar" class="meter animate blue">
+                              <span style="width: 25%"><span></span></span>
+                            </div>
+                          </div>
+                        </div>
+                      </div>
+                    </div>
+                  </div>
+  
+                  <div class="col-sm-6 col-lg-3">
+                    <div class="card card-sm">
+                      <div class="card-body">
+                        <div class="row align-items-center">
+                          <div class="col-auto">
+                            <span class="bg-facebook text-white avatar">
+                              <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-database" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z" fill="none"></path> <path d="M12 6m-8 0a8 3 0 1 0 16 0a8 3 0 1 0 -16 0"></path> <path d="M4 6v6a8 3 0 0 0 16 0v-6"></path> <path d="M4 12v6a8 3 0 0 0 16 0v-6"></path></svg>
+                            </span>
+                          </div>
+                          <div class="col">
+                            <div class="font-weight-medium">
+                              <label id="disk-text" class="disk-text mb-1" for="disk">DISK 0%</label>
+                            </div>
+                            <div id="disk-bar" class="meter animate red">
+                              <span style="width: 25%"><span></span></span>
+                            </div>
+                          </div>
+                        </div>
+                      </div>
+                    </div>
+                  </div>
+  
+  
+                </div>
+              </div>
+  
+  
+              <!-- inserted here from  -->
+              
+  
+            </div>
           </div>
         </div>
+        
+        <%- include('footer.ejs') %>
+        
       </div>
-      
-      <%- include('footer.ejs') %>
-      
     </div>
-  </div>
     
 
   <!-- Libs JS -->