diff --git a/document_roots/webhost/assets/css/style.css b/document_roots/webhost/assets/css/style.css index 6e27941..f653b57 100644 --- a/document_roots/webhost/assets/css/style.css +++ b/document_roots/webhost/assets/css/style.css @@ -1,3 +1,29 @@ +/* Sticky Footer Start */ +html { + position:relative; + min-height:100%; +} + +body { + margin-bottom:60px; +} + +.sticky-footer { + position:absolute; + bottom:0; + width:100%; + height:60px; + line-height:60px; + background-color:#E0EBF5; +} +/* Sticky Footer End */ + +/* Navbar Start */ .navbar { background-color:#E0EBF5 !important; } + +#logoutForm > button { + cursor:pointer; +} +/* Navbar End */ diff --git a/document_roots/webhost/assets/js/formHandlers/login.js b/document_roots/webhost/assets/js/formHandlers/login.js new file mode 100644 index 0000000..3d12a41 --- /dev/null +++ b/document_roots/webhost/assets/js/formHandlers/login.js @@ -0,0 +1,31 @@ +jQuery('#loginForm').on('submit', function(e){ + e.preventDefault(); + + var formData = {}; + for(var y = 0, yy = this.length; y < yy; y++) { + var input = this[y]; + if(input.name) { + formData[input.name] = input.value; + } + } + + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(formData)); + + xhr.onloadend = function() { + if(xhr.status == 200 || xhr.status == 204) { + jQuery('.index-alert').html('Login Success: Redirecting in 2 seconds...'); + jQuery('.index-alert').removeClass('alert-danger').addClass('alert-success').removeClass('d-none'); + + setTimeout(function(){ + window.location.href = "/gPanel.html"; + }, 2000); + } + else { + jQuery('.index-alert').html("Login Error: " + xhr.response); + jQuery('.index-alert').removeClass('alert-success').addClass('alert-danger').removeClass('d-none'); + } + } +}); diff --git a/document_roots/webhost/assets/js/formHandlers/logout.js b/document_roots/webhost/assets/js/formHandlers/logout.js new file mode 100644 index 0000000..cf2e99a --- /dev/null +++ b/document_roots/webhost/assets/js/formHandlers/logout.js @@ -0,0 +1,20 @@ +jQuery('#logoutForm').on('submit', function(e){ + e.preventDefault(); + + var check = confirm('Are you sure you want to logut?'); + + if(check) { + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.send(); + + xhr.onloadend = function() { + if(xhr.status == 200 || xhr.status == 204) { + window.location.href = '/'; + } + else { + alert('An error has occurred. Please contact your server\'s administrator.'); + } + } + } +}); diff --git a/document_roots/webhost/assets/js/formHandlers/register.js b/document_roots/webhost/assets/js/formHandlers/register.js new file mode 100644 index 0000000..074a719 --- /dev/null +++ b/document_roots/webhost/assets/js/formHandlers/register.js @@ -0,0 +1,27 @@ +jQuery('#registerForm').on('submit', function(e){ + e.preventDefault(); + + var formData = {}; + for(var y = 0, yy = this.length; y < yy; y++) { + var input = this[y]; + if(input.name) { + formData[input.name] = input.value; + } + } + + var xhr = new XMLHttpRequest(); + xhr.open(jQuery(this).attr('method'), jQuery(this).attr('action'), true); + xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); + xhr.send(JSON.stringify(formData)); + + xhr.onloadend = function() { + if(xhr.status == 200 || xhr.status == 204) { + jQuery('.index-alert').html('Register Success: You may now login.'); + jQuery('.index-alert').removeClass('alert-danger').addClass('alert-success').removeClass('d-none'); + } + else { + jQuery('.index-alert').html("Register Error: " + xhr.response); + jQuery('.index-alert').removeClass('alert-success').addClass('alert-danger').removeClass('d-none'); + } + } +}); diff --git a/document_roots/webhost/assets/js/formHandlers/search.js b/document_roots/webhost/assets/js/formHandlers/search.js new file mode 100644 index 0000000..e659a8a --- /dev/null +++ b/document_roots/webhost/assets/js/formHandlers/search.js @@ -0,0 +1,4 @@ +jQuery('#searchForm').on('submit', function(e){ + e.preventDefault(); + alert('Search functionality coming soon.'); +}); diff --git a/document_roots/webhost/assets/js/main.js b/document_roots/webhost/assets/js/main.js deleted file mode 100644 index 8b13789..0000000 --- a/document_roots/webhost/assets/js/main.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/document_roots/webhost/gPanel.html b/document_roots/webhost/gPanel.html index b1100bd..599f395 100644 --- a/document_roots/webhost/gPanel.html +++ b/document_roots/webhost/gPanel.html @@ -7,19 +7,23 @@ + @@ -40,11 +44,25 @@ + + - + + diff --git a/document_roots/webhost/index.html b/document_roots/webhost/index.html index 9b9dc44..2fa7516 100644 --- a/document_roots/webhost/index.html +++ b/document_roots/webhost/index.html @@ -12,43 +12,92 @@ -
-
-
- -
-
- -
+
+
+ +
+
-
- -
-
- -
+ +
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
- - + +
+
+
+ +
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+ Register is Temporary, for development purposes only. +
+ +
+ + - + + + diff --git a/pkg/api/user.go b/pkg/api/user.go index e23110d..3435966 100644 --- a/pkg/api/user.go +++ b/pkg/api/user.go @@ -48,7 +48,7 @@ func UserAuthentication(res http.ResponseWriter, req *http.Request) bool { err = ds.Get(database.BUCKET_USERS, []byte(userRequestData.User), &userDatabaseData) if err == database.ErrKeyNotExist { - http.Error(res, "User does not exist in database", http.StatusUnauthorized) + http.Error(res, "User does not exist.", http.StatusUnauthorized) return false } @@ -134,5 +134,6 @@ func UserLogout(res http.ResponseWriter, req *http.Request) bool { return false } + res.WriteHeader(http.StatusNoContent) return true } diff --git a/pkg/networking/session_store.go b/pkg/networking/session_store.go index f50ce53..62181a4 100644 --- a/pkg/networking/session_store.go +++ b/pkg/networking/session_store.go @@ -32,7 +32,6 @@ func (s *store) Set(res http.ResponseWriter, req *http.Request, key string, valu session, err := s.handle.Get(req, s.cookieName) if err != nil { - http.Error(res, http.StatusText(500), http.StatusInternalServerError) return err } @@ -50,7 +49,6 @@ func (s *store) Read(res http.ResponseWriter, req *http.Request, key string) (in session, err := s.handle.Get(req, s.cookieName) if err != nil { - http.Error(res, http.StatusText(500), http.StatusInternalServerError) return nil, err } @@ -62,7 +60,6 @@ func (s *store) Delete(res http.ResponseWriter, req *http.Request) error { session, err := s.handle.Get(req, s.cookieName) if err != nil { - http.Error(res, http.StatusText(500), http.StatusInternalServerError) return err } diff --git a/pkg/webhost/webhost.go b/pkg/webhost/webhost.go index 57fcedf..2232fd9 100644 --- a/pkg/webhost/webhost.go +++ b/pkg/webhost/webhost.go @@ -38,6 +38,9 @@ func reqAuth(path string) bool { dismissibleFiles := []string{ "api_testing.html", "index.html", + "user_auth", + "user_register", + "user_logut", } for _, f := range dismissibleFiles { if strings.HasSuffix(path, f) { @@ -58,27 +61,24 @@ func (priv *PrivateHost) ServeHTTP(w http.ResponseWriter, req *http.Request) { path = (priv.Directory + path) } - var auth interface{} = true if reqAuth(path) { store := networking.GetStore(networking.COOKIES_USER_AUTH) - auth, err := store.Read(w, req, "auth") + session_value, err := store.Read(w, req, "auth") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - auth, ok := auth.(bool) - if !ok { - http.Error(w, err.Error(), http.StatusInternalServerError) + if session_value == nil { + http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return } - } - if !auth.(bool) { - routing.HttpThrowStatus(http.StatusUnauthorized, w) - logging.Console(logging.PRIVATE_PREFIX, logging.NORMAL_LOG, "Path \""+path+"\" rendered a 401 error.") - return + if auth, ok := session_value.(bool); !ok || !auth { + http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) + return + } } isApi, _ := api.HandleAPI(path, w, req)