mirror of
https://github.com/donl/gPanel.git
synced 2026-06-30 06:12:06 -06:00
Merge pull request #52 from george-e-shaw-iv/master
Login/Logout Authorization Front End
This commit is contained in:
commit
877c0f8a9d
11 changed files with 209 additions and 37 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
31
document_roots/webhost/assets/js/formHandlers/login.js
Normal file
31
document_roots/webhost/assets/js/formHandlers/login.js
Normal file
|
|
@ -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('<strong>Login Success: </strong>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("<strong>Login Error: </strong>" + xhr.response);
|
||||
jQuery('.index-alert').removeClass('alert-success').addClass('alert-danger').removeClass('d-none');
|
||||
}
|
||||
}
|
||||
});
|
||||
20
document_roots/webhost/assets/js/formHandlers/logout.js
Normal file
20
document_roots/webhost/assets/js/formHandlers/logout.js
Normal file
|
|
@ -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.');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
27
document_roots/webhost/assets/js/formHandlers/register.js
Normal file
27
document_roots/webhost/assets/js/formHandlers/register.js
Normal file
|
|
@ -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('<strong>Register Success: </strong>You may now login.');
|
||||
jQuery('.index-alert').removeClass('alert-danger').addClass('alert-success').removeClass('d-none');
|
||||
}
|
||||
else {
|
||||
jQuery('.index-alert').html("<strong>Register Error: </strong>" + xhr.response);
|
||||
jQuery('.index-alert').removeClass('alert-success').addClass('alert-danger').removeClass('d-none');
|
||||
}
|
||||
}
|
||||
});
|
||||
4
document_roots/webhost/assets/js/formHandlers/search.js
Normal file
4
document_roots/webhost/assets/js/formHandlers/search.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
jQuery('#searchForm').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
alert('Search functionality coming soon.');
|
||||
});
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -7,19 +7,23 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<link type="text/css" rel="stylesheet" href="assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md navbar-light mb-4">
|
||||
<a class="navbar-brand" href="#">gPanel</a>
|
||||
<a class="navbar-brand text-primary" href="#">gPanel</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||||
<form class="form-inline mt-2 mt-md-0 ml-auto">
|
||||
<form id="searchForm" method="POST" action="#" class="form-inline mt-2 mt-md-0 ml-auto">
|
||||
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
|
||||
<button class="btn btn-outline-primary my-2 my-sm-0" type="submit">Search</button>
|
||||
</form>
|
||||
<form id="logoutForm" method="POST" action="user_logout" class="form-inline mt-2 mt-md-0 ml-3">
|
||||
<button class="btn btn-primary my-2 my-sm-0" type="submit">Logout</button>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
|
@ -40,11 +44,25 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="sticky-footer">
|
||||
<div class="container">
|
||||
<div class="row no-gutters">
|
||||
<div class="col-md-6 col-12">
|
||||
<p class="text-muted m-0">Managed by <a target="_blank" href="http://ennovar.io/">Ennovar</a></p>
|
||||
</div>
|
||||
<div class="col-md-6 col-12 d-flex justify-content-center justify-content-md-end">
|
||||
<p class="text-muted m-0">Contribute on <a target="_blank" href="https://github.com/Ennovar/gPanel">Github <i class="fa fa-github" aria-hidden="true"></i></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="assets/js/main.js"></script>
|
||||
<script type="text/javascript" src="assets/js/formHandlers/search.js"></script>
|
||||
<script type="text/javascript" src="assets/js/formHandlers/logout.js"></script>
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -12,43 +12,92 @@
|
|||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md navbar-light mb-4">
|
||||
<a class="navbar-brand" href="#">gPanel</a>
|
||||
<a class="navbar-brand text-primary" href="#">gPanel</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||||
<form class="form-inline mt-2 mt-md-0 ml-auto">
|
||||
<form id="searchForm" method="POST" action="#" class="form-inline mt-2 mt-md-0 ml-auto">
|
||||
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
|
||||
<button class="btn btn-outline-primary my-2 my-sm-0" type="submit">Search</button>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container d-flex justify-content-center align-items-center">
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="loginUsername">Username</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></div>
|
||||
<input type="text" class="form-control" id="loginUsername" placeholder="Username...">
|
||||
</div>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-12 d-flex justify-content-center align-items-center">
|
||||
<div class="alert index-alert d-none" role="alert"></div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="loginPassword">Password</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input type="text" class="form-control" id="loginPassword" placeholder="Password...">
|
||||
</div>
|
||||
|
||||
<div class="col-12 d-flex justify-content-center align-items-center">
|
||||
<form id="loginForm" method="POST" action="user_auth">
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="loginUsername">Username</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></div>
|
||||
<input name="user" type="text" class="form-control" id="loginUsername" placeholder="Username">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="loginPassword">Password</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input name="pass" type="password" class="form-control" id="loginPassword" placeholder="Password">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Login</button>
|
||||
</form>
|
||||
|
||||
<div class="col-12 d-flex justify-content-center align-items-center mt-5">
|
||||
<form id="registerForm" method="POST" action="user_register">
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="loginUsername">Username</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-user" aria-hidden="true"></i></div>
|
||||
<input name="user" type="text" class="form-control" id="loginUsername" placeholder="Username">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="loginPassword">Password</label>
|
||||
<div class="input-group mb-2">
|
||||
<div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
|
||||
<input name="pass" type="password" class="form-control" id="loginPassword" placeholder="Password">
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Register</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="col-12 d-flex justify-content-center align-items-center mt-2">
|
||||
<small class="text-muted">Register is Temporary, for development purposes only.</small>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer class="sticky-footer">
|
||||
<div class="container">
|
||||
<div class="row no-gutters">
|
||||
<div class="col-md-6 col-12">
|
||||
<p class="text-muted m-0">Managed by <a target="_blank" href="http://ennovar.io/">Ennovar</a></p>
|
||||
</div>
|
||||
<div class="col-md-6 col-12 d-flex justify-content-center justify-content-md-end">
|
||||
<p class="text-muted m-0">Contribute on <a target="_blank" href="https://github.com/Ennovar/gPanel">Github <i class="fa fa-github" aria-hidden="true"></i></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="assets/js/main.js"></script>
|
||||
<script type="text/javascript" src="assets/js/formHandlers/login.js"></script>
|
||||
<script type="text/javascript" src="assets/js/formHandlers/register.js"></script>
|
||||
<script type="text/javascript" src="assets/js/formHandlers/search.js"></script>
|
||||
<!-- KEEP AT BOTTOM OF BODY TAGS -->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue