feat: fetch, url params handling
This commit is contained in:
parent
cbcf3067cb
commit
135df93d49
1 changed files with 59 additions and 14 deletions
|
@ -7,23 +7,68 @@
|
|||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
|
||||
<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background-color: black;
|
||||
color: white;
|
||||
}
|
||||
label {
|
||||
font-size: 20px;
|
||||
}
|
||||
input {
|
||||
background-color: #282828;
|
||||
border: none;
|
||||
border-bottom: 1px solid white;
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
margin-bottom: 20px;
|
||||
padding: 10px;
|
||||
}
|
||||
button {
|
||||
background-color: #4CAF50;
|
||||
border: none;
|
||||
color: white;
|
||||
font-size: 22px;
|
||||
padding: 10px 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #3e8e41;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Sign In</h1>
|
||||
<form action="/login" method="GET">
|
||||
<div class="form-group">
|
||||
<label for="client_id">User Name</label>
|
||||
<input type="text" class="form-control" name="client_id" required placeholder="Please enter your user name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="client_secret">Password</label>
|
||||
<input type="password" class="form-control" name="client_secret" placeholder="Please enter your password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-success">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="container">
|
||||
<h1>Login</h1>
|
||||
<form>
|
||||
<div class="form-group">
|
||||
<label for="user_login">Username</label>
|
||||
<input type="text" class="form-control" name="user_login" required placeholder="Enter your username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="client_secret">Password</label>
|
||||
<input type="password" class="form-control" name="client_secret" placeholder="Enter your password">
|
||||
</div>
|
||||
<button id="login-btn">Login</button>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
const loginBtn = document.getElementById('login-btn');
|
||||
loginBtn.addEventListener('click', (event) => {
|
||||
event.preventDefault();
|
||||
const userLogin = document.querySelector('input[name="user_login"]').value;
|
||||
const clientSecret = document.querySelector('input[name="client_secret"]').value;
|
||||
const backRedirectionAddress = new URLSearchParams(window.location.search).get('back_redirection_address');
|
||||
fetch('http://auth-server/login?user_login=${userLogin}&client_secret=${clientSecret}')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const accessToken = data.access_token;
|
||||
window.location.href = '${backRedirectionAddress}?access_token=${accessToken}&user_login=${userLogin}';
|
||||
})
|
||||
.catch(error => console.error(error));
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue