-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
257 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
let form = document.getElementById('login-form'); | ||
let loginSubmitButton = document.getElementById('login-submit-button'); | ||
let loginErrorMsg = document.getElementById('login-error-msg'); | ||
let loginErrorMsgContent = document.getElementById('login-error-msg-content'); | ||
|
||
async function login() { | ||
let formData = new FormData(form); | ||
let myHeaders = new Headers(); | ||
myHeaders.append('Content-Type', 'application/json'); | ||
const response = await fetch('/admin/login', { | ||
method: 'post', | ||
body: JSON.stringify({ | ||
username: formData.get('username'), | ||
passwd: formData.get('passwd') | ||
}), | ||
headers: myHeaders, | ||
}); | ||
const result = await response.json(); | ||
if (response.status === 401 && result.msg) { | ||
loginErrorMsg?.removeAttribute('hidden'); | ||
loginErrorMsgContent.textContent = result.msg; | ||
} else { | ||
localStorage.setItem('jwt', result.access_token); | ||
window.location.replace("/admin"); | ||
} | ||
}; | ||
|
||
form.addEventListener('keyup', function (e) { | ||
if (e.key === 'Enter' || e.keyCode === 13) { | ||
login(); | ||
} | ||
}); | ||
|
||
loginSubmitButton.onclick = (e) => { | ||
e.preventDefault(); | ||
login(); | ||
}; | ||
|
||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>{{ site.title }}::login</title> | ||
{#<link rel="icon" href="img/favicon.ico">#} | ||
<!-- CSS FILES --> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='css/uikit.min.css')}} " /> | ||
</head> | ||
<body class="uk-flex uk-flex-center uk-flex-middle uk-background-muted uk-height-viewport" data-uk-height-viewport> | ||
<div class="uk-position-bottom-center uk-position-small uk-visible@m uk-position-z-index"> | ||
<span class="uk-text-small uk-text-muted">© 2023 naturedb</span> | ||
</div> | ||
<div class="uk-width-medium uk-padding-small"> | ||
<!-- login --> | ||
<h3>{{ site.name.upper() }} Login</h3> | ||
{% with messages = get_flashed_messages() %} | ||
{% if messages %} | ||
{% for message in messages %} | ||
<div class="uk-alert-danger" uk-alert> | ||
<a class="uk-alert-close" uk-close></a> | ||
<p>{{ message }}</p> | ||
</div> | ||
{% endfor %} | ||
{% endif %} | ||
{% endwith %} | ||
<div class="uk-alert-danger" id="login-error-msg" uk-alert hidden> | ||
<a class="uk-alert-close" uk-close></a> | ||
<p id="login-error-msg-content"></p> | ||
</div> | ||
<form class="toggle-class" {#action="{{ url_for('admin.login') }}" method="POST"#} id="login-form"> | ||
<fieldset class="uk-fieldset"> | ||
<div class="uk-margin-small"> | ||
<div class="uk-inline uk-width-1-1"> | ||
<span class="uk-form-icon uk-form-icon-flip" data-uk-icon="icon: user"></span> | ||
<input class="uk-input uk-border-pill" required placeholder="Username" type="text" name="username"> | ||
</div> | ||
</div> | ||
<div class="uk-margin-small"> | ||
<div class="uk-inline uk-width-1-1"> | ||
<span class="uk-form-icon uk-form-icon-flip" data-uk-icon="icon: lock"></span> | ||
<input class="uk-input uk-border-pill" required placeholder="Password" type="password" name="passwd"> | ||
</div> | ||
</div> | ||
{#<div class="uk-margin-small"> | ||
<label><input class="uk-checkbox" type="checkbox"> Keep me logged in</label> | ||
</div>#} | ||
<div class="uk-margin-bottom"> | ||
<button type="button" class="uk-button uk-button-primary uk-border-pill uk-width-1-1" id="login-submit-button">LOG IN</button> | ||
</div> | ||
</fieldset> | ||
</form> | ||
<!-- /login --> | ||
|
||
<!-- recover password --> | ||
<form class="toggle-class" action="login-dark.html" hidden> | ||
<div class="uk-margin-small"> | ||
<div class="uk-inline uk-width-1-1"> | ||
<span class="uk-form-icon uk-form-icon-flip" data-uk-icon="icon: mail"></span> | ||
<input class="uk-input uk-border-pill" placeholder="E-mail" required type="text"> | ||
</div> | ||
</div> | ||
<div class="uk-margin-bottom"> | ||
<button type="submit" class="uk-button uk-button-primary uk-border-pill uk-width-1-1">SEND PASSWORD</button> | ||
</div> | ||
</form> | ||
<!-- /recover password --> | ||
|
||
<!-- action buttons --> | ||
<div> | ||
<div class="uk-text-center"> | ||
<a class="uk-link-reset uk-text-small toggle-class" data-uk-toggle="target: .toggle-class ;animation: uk-animation-fade">Forgot your password?</a> | ||
<a class="uk-link-reset uk-text-small toggle-class" data-uk-toggle="target: .toggle-class ;animation: uk-animation-fade" hidden><span data-uk-icon="arrow-left"></span> Back to Login</a> | ||
</div> | ||
</div> | ||
<!-- action buttons --> | ||
</div> | ||
|
||
<!-- JS FILES --> | ||
<script src="{{ url_for('static', filename='js/uikit.min.js') }}"></script> | ||
<script src="{{ url_for('static', filename='js/uikit-icons.min.js') }}"></script> | ||
<script src="{{ url_for('static', filename='js/login.js') }}"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters