mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-07-16 18:48:15 +03:00
Add authentication
This commit is contained in:
parent
a78c9f3dd4
commit
a5fbb7b58a
13 changed files with 306 additions and 7 deletions
|
@ -64,6 +64,8 @@
|
|||
<button style="margin-left: 0.5em;" type="button" class="btn btn-outline-danger btn-sm" data-toggle="modal"
|
||||
data-target="#modal_apply_config"><i class="nav-icon fas fa-check"></i> Apply
|
||||
Config</button>
|
||||
<button onclick="location.href='/logout';" style="margin-left: 0.5em;" type="button"
|
||||
class="btn btn-outline-danger btn-sm"><i class="nav-icon fas fa-sign-out-alt"></i> Logout</button>
|
||||
</nav>
|
||||
</nav>
|
||||
<!-- /.navbar -->
|
||||
|
@ -82,7 +84,7 @@
|
|||
<!-- Sidebar user (optional) -->
|
||||
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
|
||||
<div class="image">
|
||||
<img src="static/dist/img/user2-160x160.jpg" class="img-circle elevation-2">
|
||||
<i class="nav-icon fas fa-2x fa-user"></i>
|
||||
</div>
|
||||
<div class="info">
|
||||
<a href="#" class="d-block">{{template "username" .}}</a>
|
||||
|
|
|
@ -13,7 +13,7 @@ Wireguard Clients
|
|||
{{end}}
|
||||
|
||||
{{define "username"}}
|
||||
Admin
|
||||
{{ .username }}
|
||||
{{end}}
|
||||
|
||||
{{define "page_title"}}
|
||||
|
|
|
@ -6,7 +6,7 @@ Global Settings
|
|||
{{end}}
|
||||
|
||||
{{define "username"}}
|
||||
Admin
|
||||
{{ .username }}
|
||||
{{end}}
|
||||
|
||||
{{define "page_title"}}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<p class="login-box-msg">Sign in to start your session</p>
|
||||
<form action="" method="post">
|
||||
<div class="input-group mb-3">
|
||||
<input type="username" class="form-control" placeholder="Username">
|
||||
<input id="username" type="username" class="form-control" placeholder="Username">
|
||||
<div class="input-group-append">
|
||||
<div class="input-group-text">
|
||||
<span class="fas fa-envelope"></span>
|
||||
|
@ -39,7 +39,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<input type="password" class="form-control" placeholder="Password">
|
||||
<input id="password" type="password" class="form-control" placeholder="Password">
|
||||
<div class="input-group-append">
|
||||
<div class="input-group-text">
|
||||
<span class="fas fa-lock"></span>
|
||||
|
@ -57,11 +57,14 @@
|
|||
</div>
|
||||
<!-- /.col -->
|
||||
<div class="col-4">
|
||||
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
|
||||
<button id="btn_login" type="button" class="btn btn-primary btn-block">Sign In</button>
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
</form>
|
||||
<div class="text-center mb-3">
|
||||
<p id="message"></p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /.login-card-body -->
|
||||
</div>
|
||||
|
@ -75,5 +78,43 @@
|
|||
<script src="static/dist/js/adminlte.min.js"></script>
|
||||
|
||||
</body>
|
||||
<script>
|
||||
function redirectNext() {
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
var nextURL = urlParams.get('next');
|
||||
if (nextURL) {
|
||||
window.location.href = nextURL;
|
||||
} else {
|
||||
window.location.href = '/';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#btn_login').click(function () {
|
||||
var username = $("#username").val();
|
||||
var password = $("#password").val();
|
||||
var data = {"username": username, "password": password}
|
||||
console.log(data);
|
||||
|
||||
$.ajax({
|
||||
cache: false,
|
||||
method: 'POST',
|
||||
url: '/login',
|
||||
dataType: 'json',
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify(data),
|
||||
success: function(data) {
|
||||
document.getElementById("message").innerHTML = '<p style="color:green">' + data['message'] + '</p>';
|
||||
// redirect after logging in successfully
|
||||
redirectNext();
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
||||
document.getElementById("message").innerHTML = '<p style="color:red">' + responseJson['message'] + '</p>';
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</html>
|
||||
|
|
|
@ -6,7 +6,7 @@ Wireguard Server
|
|||
{{end}}
|
||||
|
||||
{{define "username"}}
|
||||
Admin
|
||||
{{ .username }}
|
||||
{{end}}
|
||||
|
||||
{{define "page_title"}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue