This commit is contained in:
Leo 2024-01-21 20:02:12 +08:00
commit 8f37282f9a
9 changed files with 4421 additions and 216 deletions

View File

@ -149,7 +149,7 @@ app.auth = (function (app) {
function setToken(token) {
localStorage.setItem("APIToken", token);
}
/*
function setUserId(userid) {
console.log("userid", userid);
localStorage.setItem("userid", userid);
@ -158,6 +158,7 @@ app.auth = (function (app) {
function setUsername(username) {
localStorage.setItem("username", username);
}
*/
function getToken() {
return localStorage.getItem("APIToken");
@ -167,6 +168,7 @@ app.auth = (function (app) {
if (getToken()) {
return app.api.get("user/me", function (error, data) {
if (!error) app.auth.user = data;
$.scope.getUsername.push(data.username);
return callback(error, data);
});
} else {
@ -204,8 +206,6 @@ app.auth = (function (app) {
});
localStorage.removeItem("APIToken");
localStorage.removeItem("userid");
localStorage.removeItem("username");
callback();
}
@ -244,8 +244,6 @@ app.auth = (function (app) {
return {
getToken: getToken,
setToken: setToken,
setUserId: setUserId,
setUsername: setUsername,
isLoggedIn: isLoggedIn,
//logIn: logIn,
logOut: logOut,

View File

@ -0,0 +1,305 @@
(function($, Mustache){
'use strict';
if (!$.scope) {
$.scope = {};
}
var make = function( element ){
//construct array
function makeArray( input , index ){
var result = [];
Object.defineProperty( result, "__repeatId", {
value: repeatId,
writable: true,
enumerable: false,
configurable: true
} );
Object.defineProperty( result, "__rq_template", {
value: '',
writable: true,
enumerable: false,
configurable: true
} );
Object.defineProperty( result, "__jq_index", {
value: index,
writable: true,
enumerable: false,
configurable: true
} );
function removeEmpty(){
if(result.__jq_empty){
result.__jq_empty.remove();
delete result.__jq_empty;
}
}
result.splice = function(inputValue, ...args){
//splice does all the heavy lifting by interacting with the DOM elements.
var toProto = [...args]
var index;
//if a string is submitted as the index, try to match it to index number
if( typeof arguments[0] === 'string' ){
index = this.indexOf( arguments[0] );//set where to start
if ( index === -1 ) {
return [];
}
}else{
index = arguments[0]; //set where to start
}
toProto.unshift(index)
var howMany = arguments[1]; //sets the amount of fields to remove
var args = Array.prototype.slice.call( arguments ); // coverts arguments into array
var toAdd = args.slice(2); // only keeps fields to add to array
// if the starting point is higher then the total index count, start at the end
if( index > this.length ) {
index = this.length;
}
// if the starting point is negative, start form the end of the array, minus the start point
if( index < 0 ) {
index = this.length - Math.abs( index );
}
// if there are things to add, figure out the how many new indexes we need
if( !howMany && howMany !== 0 ) {
howMany = this.length - index;
}
//not sure why i put this here... but it does matter!
if( howMany > this.length - index ) {
howMany = this.length - index;
}
//figure out how many positions we need to shift the current elements
var shift = toAdd.length - howMany;
// figure out how big the new array will be
// var newLength = this.length + shift;
//removes fields from array based on howMany needs to be removed
for( var i = index; i < +index+howMany; i++ ) {
this.__take.apply( this[index].__jq_$el );
// this.__take.apply( $( '.jq-repeat-'+ this.__repeatId +'[jq-repeat-index="'+ ( i + index ) +'"]' ) );
}
//re-factor element index's
for(var i = 0; i < this.length; i++){
if( i >= index){
this[i].__jq_$el.attr( 'jq-repeat-index', i+shift );
}
}
//if there are fields to add to the array, add them
if( toAdd.length > 0 ){
removeEmpty()
//$.each( toAdd, function( key, value ){
for(var I = 0; I < toAdd.length; I++){
//figure out new elements index
var key = I + index;
// apply values to template
var render = Mustache.render( this.__rq_template, {__id:I, ...toAdd[I]} );
//set call name and index keys to DOM element
var $render = $( render ).addClass( 'jq-repeat-'+ this.__repeatId ).attr( 'jq-repeat-index', key );
//if add new elements in proper stop, or after the place holder.
if( key === 0 ){
$( '.jq-repeat-'+ this.__repeatId +'[jq-repeat-index="holder"]' ).after( $render );
}else{
$( '.jq-repeat-'+ this.__repeatId +'[jq-repeat-index="' + ( key -1 ) + '"]' ).after( $render );
}
Object.defineProperty( toAdd[I], "__jq_$el", {
value: $render,
writable: true,
enumerable: false,
configurable: true
} );
//animate element
this.__put.apply($render, [toAdd[I]]);
}
}
//set and return new array
return Array.prototype.splice.apply(this, toProto);
};
result.push = function(){
//add one or more objects to the array
//set the index value, if none is set make it zero
var index = this.length || 0;
//loop each passed object and pass it to slice
for (var i = 0 ; i < arguments.length; ++i) {
this.splice( ( index + i ), 0, arguments[i] );
}
//return new array length
return this.length;
};
result.unshift = function(item){
return this.splice(0, 0, item);
};
result.pop = function(){
//remove and return array element
return this.splice( -1, 1 )[0];
};
result.reverse = function() {
var temp = this.splice( 0 );
Array.prototype.reverse.apply( temp );
for( var i = 0; i < temp.length; i++ ){
this.push( temp[i] );
}
return this;
};
result.shift = function() {
return this.splice( 0, 1 )[0];
};
result.loop = function(){
var temp = this[0];
this.splice( 0,1 );
this.push( temp );
return temp;
};
result.loopUp = function(){
var temp = this[this.length-1];
this.splice( -1, 1 );
this.splice( 0, 0, temp );
return temp;
};
result.indexOf = function( key, value ){
if( !value ){
value = arguments[0];
key = this.__jq_index;
}
for ( var index = 0; index < this.length; ++index ) {
if( this[index][key] === value ){
return index;
}
}
return -1;
};
result.update = function( key, value, update ){
//set variables using sting for index
// If update is called with no index/key, assume its the 0
if(typeof key === 'object'){
if(this[0]){
return this.update(0, key);
}
return this.splice(0, 1, key);
}
if( !update ){
update = arguments[1];
value = arguments[0];
key = this.__jq_index;
}
var index = this.indexOf( key, value );
if(index === -1) {
return [];
}
var object = $.extend( true, {}, this[index], update );
return this.splice( index, 1, object )[0];
};
result.__put = function(){
this.show();
};
result.__take = function(){
this.remove();
};
if(!input) {
return result;
}
$.each( input, function( key, value ){
var type = typeof value;
if( type === 'object' ){
result.push( value );
}else if( type === 'string' ){
Object.defineProperty( result, "__jq_index", {
value: value,
writable: true,
enumerable: false,
configurable: true
} );
} else if ( type === 'function'){
Object.defineProperty( result, value.name, {
value: value,
writable: true,
enumerable: false,
configurable: true
} );
}
} );
return result;
}
var $this = $( element );
var repeatId = $this.attr( 'jq-repeat' );
var index = $this.attr( 'jq-repeat-index' );
var tempId = repeatId + 'Template';
var templateId = $( '#' + tempId ).html();
var empty = $(`[jq-repeat-defualt="${repeatId}"]`);
$this.removeAttr( 'jq-repeat' );
$this.removeAttr( 'jq-repeat-index' );
var template = element.outerHTML
$this.replaceWith( '<script type="x-tmpl-mustache" id="' + tempId + '" class="jq-repeat-' + repeatId + ' " jq-repeat-index="holder"><\/script>' );
Mustache.parse(templateId); // optional, speeds up future uses
$.scope[repeatId] = makeArray($.scope[repeatId], index);
$.scope[repeatId].__rq_template = template;
$.scope[repeatId].__jq_empty = empty;
};
$( document ).ready( function(){
console.log('jq-repeat', $.scope)
//$.jqrepeat = $.scope
$( '[jq-repeat]' ).each(function(key, value){
make(value);
});
$(document).on('DOMNodeInserted', function(e) {
if ( $(e.target).is('[jq-repeat]') ){
make( e.target );
}else{
var t = $(e.target).find('[jq-repeat]');
t.each(function(key, value){
make(value);
});
}
});
} );
})(jQuery, Mustache);

File diff suppressed because one or more lines are too long

View File

@ -37,70 +37,54 @@ module.exports = router;
*/
'use strict';
"use strict";
var router = require('express').Router();
var router = require("express").Router();
//landing page of index
router.get('/', function(req, res, next) {
res.render('index');
router.get("/", function (req, res, next) {
res.render("index");
});
//news page
router.get('/news', function(req, res, next) {
res.render('news');
router.get("/news", function (req, res, next) {
res.render("news");
});
//learn more page
router.get('/learnmore', function(req, res, next) {
res.render('learnmore');
router.get("/learnmore", function (req, res, next) {
res.render("learnmore");
});
//login | register page
router.get('/login', function(req, res, next) {
res.render('signuplogin');
router.get("/login", function (req, res, next) {
res.render("signuplogin");
});
//profile page
router.get('/profile', function(req, res, next) {
res.render('profile');
router.get("/profile", function (req, res, next) {
res.render("profile");
});
//forgot password page
router.get('/forgotPassword', function(req, res, next) {
res.render('forgotPassword');
});
//contact page
router.get('/contact', function(req, res, next) {
res.render('contact');
});
//api doc
router.get('/api', function(req, res, next) {
res.render('api');
});
//forget password page
router.get('/forgotPassword', function(req, res, next) {
res.render('forgotPassword');
router.get("/forgotPassword", function (req, res, next) {
res.render("forgotPassword");
});
//resetted password page
router.get('/resetpassword', function(req, res, next) {
res.render('resetpassword');
router.get("/resetpassword", function (req, res, next) {
res.render("resetpassword");
});
//learn more page
router.get('/learnmore', function(req, res, next) {
res.render('learnmore');
//contact page
router.get("/contact", function (req, res, next) {
res.render("contact");
});
//profile page
router.get('/profile', function(req, res, next) {
res.render('profile');
//api doc
router.get("/api", function (req, res, next) {
res.render("api");
});
module.exports = router;

View File

@ -86,10 +86,9 @@
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="js/learnmore.js"></script>
<script src="js/contact.js"></script>
<script src="js/search.js"></script>
<script src="js/api.js"></script>
<script src="js/learnmore.js"></script>
<script src="js/search.js"></script>
</body>
</html>

View File

@ -23,6 +23,9 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<!-- Mustache JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.1/mustache.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.1/mustache.js"></script>
<!-- jquery app.js -->
@ -100,6 +103,4 @@
</div>
</div>
</nav>
</body>
</html>

View File

@ -1,9 +1,9 @@
<%- include('logintop') %>
<script type="text/javascript">
<script type="text/javascript">
app.auth.redirectIfLoggedIn();
</script>
</script>
<body>
<body>
<section class="wrapper">
<div class="form signup iot-card">
<!--<div class="form signup card" -->
@ -41,6 +41,13 @@
</form>
</div>
<input type="text" name="userInfo" placeholder="Email address | Username" required />
<input type="password" name="password" placeholder="Password" required />
<a href="/resetPassword">Forgot password?</a>
<input type="submit" value="Login" />
</form>
</div>
<script>
const wrapper = document.querySelector(".wrapper"),
signupHeader = document.querySelector(".signup header"),
@ -55,7 +62,6 @@
</script>
</section>
</body>
</html>
</body>
</html>

View File

@ -1,49 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<meta http-equiv="cleartype" content="on">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<meta http-equiv="cleartype" content="on" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Bootstrap core CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous" />
<!-- Custom styles for this template -->
<link href="css/all.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/learnmore.css" rel="stylesheet">
<link href="css/contact.css" rel="stylesheet">
<link href="css/all.css" rel="stylesheet" />
<link href="css/style.css" rel="stylesheet" />
<link href="css/learnmore.css" rel="stylesheet" />
<link href="css/contact.css" rel="stylesheet" />
<link rel="stylesheet" href="css/api.css" media="all" />
<!-- weird api page cdn -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;1,300&family=Source+Code+Pro:wght@300&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;1,300&family=Source+Code+Pro:wght@300&display=swap"
rel="stylesheet" />
<!-- Mustache JS -->
<script src="https://sso.theta42.com/static/js/mustache.min.js"></script>
<!-- jQuery library -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script
src="https://code.jquery.com/jquery-3.7.1.min.js"
integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo="
crossorigin="anonymous"></script>
<!-- Bootstrap 5 JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
<!-- weird api page cdn -->
<!-- https://github.com/floriannicolas/API-Documentation-HTML-Template/tree/master -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.8.0/highlight.min.js"></script>
<!-- https://github.com/floriannicolas/API-Documentation-HTML-Template/tree/master -->
<script>
hljs.initHighlightingOnLoad();
</script>
<!-- jq-repeat -->
<script src="js/jq-repeat.js"></script>
<!-- jquery app.js -->
<script src="js/app.js"></script>
</head>
</head>
<!-- javascript function to check if user is auth -->
<script>
//make document ready
@ -51,33 +63,39 @@
//check if user is logged in
app.auth.isLoggedIn(function (error, data) {
if (data) {
$('#cl-logout-button').show('fast');
$('#cl-profile-button').show('fast');
$('#cl-login-button').hide('fast');
$("#cl-logout-button").show("fast");
$("#cl-profile-button").show("fast");
$("#cl-login-button").hide("fast");
} else {
$('#cl-login-button').show('fast');
$("#cl-login-button").show("fast");
}
$('body').show('fast')
$("body").show("fast");
});
});
</script>
</script>
<body>
<nav class="navbar fixed-top navbar-expand-lg navbar-dark bg-light top-nav fixed-top">
<body>
<nav
class="navbar fixed-top navbar-expand-lg navbar-dark bg-light top-nav fixed-top">
<div class="container">
<a class="navbar-brand" href="/">
<img src="images/logo.png" alt="logo" />
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive"
aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarResponsive"
aria-controls="navbarResponsive"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="fas fa-bars"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ms-auto">
<li jq-repeat="getUsername" class="nav-item">
{{ username }}
</li>
<li class="nav-item">
<a class="nav-link" href="/">Home</a>
</li>
@ -93,26 +111,36 @@
<!-- profile button -->
<div class="form-inline mt-2 mt-md-0">
<!-- Profile Button -->
<a id="cl-profile-button" class="btn btn-outline-info btn-sm my-2 my-sm-0" href="/profile" style="display: none;">
<a
id="cl-profile-button"
class="btn btn-outline-info btn-sm my-2 my-sm-0"
href="/profile"
style="display: none">
<i class="fas fa-sign-out"></i> Profile
</a>
<!-- Login Button -->
<a id="cl-login-button" class="btn btn-outline-danger btn-sm my-2 my-sm-0" onclick="app.auth.forceLogin()" style="display: none;">
<a
id="cl-login-button"
class="btn btn-outline-danger btn-sm my-2 my-sm-0"
onclick="app.auth.forceLogin()"
style="display: none">
<i class="fas fa-sign-out"></i> Login
</a>
<!-- Logout Button -->
<button id="cl-logout-button" class="btn btn-outline-danger btn-sm my-2 my-sm-0" href="/" onclick="app.auth.logOut(e => window.location.href='/')" style="display: none;">
<i class="fas fa-sign-out"></i> Logut
<button
id="cl-logout-button"
class="btn btn-outline-danger btn-sm my-2 my-sm-0"
href="/"
onclick="app.auth.logOut(e => window.location.href='/')"
style="display: none">
<i class="fas fa-sign-out"></i> Logout
</button>
</div>
</ul>
</div>
</div>
</nav>
</body>
</body>
</html>

View File

@ -1,17 +0,0 @@
//model for getting API key from database
async function getAPIKey() {
}
module.exports = { getAPIKey }