modify html

This commit is contained in:
echpochmak31 2024-01-15 20:19:23 +03:00
parent cbcf3067cb
commit 9e02980415
4 changed files with 67 additions and 56 deletions

View file

@ -1,7 +1,7 @@
{
"ContractCheckSum": "none",
"ContractCheckSum": "5e4375b9e8214ed4183659114735a94ac26033d7",
"AuthServerPort": 9096,
"WalletFile": "none",
"EndpointUrl": "url",
"WalletFile": "../../frostfs-aio/morph/node-wallet.json",
"EndpointUrl": "http://localhost:30333",
"AccountSecret": "one"
}

View file

@ -3,10 +3,6 @@ package main
import (
"auth-server/logic"
"context"
"net/url"
"os"
"strconv"
"github.com/go-oauth2/oauth2/v4/errors"
"github.com/go-oauth2/oauth2/v4/manage"
"github.com/go-oauth2/oauth2/v4/server"
@ -16,10 +12,12 @@ import (
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"log"
"log/slog"
"net/http"
"net/url"
"os"
"strconv"
)
func main() {
@ -98,12 +96,12 @@ func main() {
r.Form.Add("grant_type", r.URL.Query().Get("grant_type"))
r.Form.Add("scope", r.URL.Query().Get("scope"))
srv.HandleTokenRequest(w, r) // verifying secret
srv.HandleTokenRequest(w, r) // grants access token
})
http.HandleFunc("/register", func(writer http.ResponseWriter, request *http.Request) {
id := request.Header.Get("client_id")
secret := request.Header.Get("client_secret")
id := request.URL.Query().Get("client_id")
secret := request.URL.Query().Get("client_secret")
// check whether client exists
_, err := blockchainStorage.GetByID(context.Background(), id)
@ -115,16 +113,6 @@ func main() {
return
}
/* redundant
// add client's credentials to in memory storage
err = logic.AddInMemoryClient(id, "", "", false)
if err != nil {
slog.Error("Fault during setting client credentials", err)
writer.WriteHeader(http.StatusInternalServerError)
return
}
*/
// add client's credentials to blockchain
err = blockchainStorage.Set(&logic.StorageClientInfo{
Id: id,
@ -137,7 +125,8 @@ func main() {
return
}
writer.WriteHeader(http.StatusOK)
redirectURL := "/login.html"
http.Redirect(writer, request, redirectURL, http.StatusSeeOther)
})
// for tests, can access only with valid token (when logged in)
@ -167,10 +156,6 @@ func main() {
w.Write([]byte(errorMessage))
}
/* redundant
logic.DeleteInMemoryClient(id)
*/
}, srv))
// can access only with valid token (when logged in), deletes client and creates new one with another secret
@ -196,21 +181,6 @@ func main() {
w.Write([]byte(errorMessage))
}
/* redundant
logic.DeleteInMemoryClient(id)
*/
/*
// add client with new credentials to in memory storage
err = logic.AddInMemoryClient(id, "", "", false)
if err != nil {
slog.Error(errorMessage+" (caused by in memory storage) for client with id: "+id, err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(errorMessage))
return
}
*/
// add client with new credentials to blockchain
err = blockchainStorage.Set(&logic.StorageClientInfo{
Id: id,

View file

@ -10,20 +10,50 @@
</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>Sign In</h1>
<form id="loginForm" action="/login" method="GET">
<input type="hidden" name="grant_type" value="client_credentials" />
<input type="hidden" name="scope" value="all" />
<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">Sign In</button>
</form>
<form id="registerForm" action="/register.html" method="GET">
<button type="submit" class="btn btn-primary">Register</button>
</form>
</div>
<script>
function submitFormWithReferer(formId) {
var form = document.getElementById(formId);
var referrer = document.referrer || "";
form.insertAdjacentHTML('beforeend', '<input type="hidden" name="referer" value="' + referrer + '">');
form.submit();
}
document.getElementById("loginForm").addEventListener("submit", function (event) {
event.preventDefault();
submitFormWithReferer("loginForm");
});
document.getElementById("registerForm").addEventListener("submit", function (event) {
event.preventDefault();
submitFormWithReferer("registerForm");
});
</script>
</body>
</html>
<style>
.btn-primary {
margin-top: 10px;
}
</style>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Redirect</title>
<meta http-equiv="refresh" content="0;url=http://localhost:9096/login.html">
</head>
<body>
<p>If you are not redirected, <a href="http://localhost:9096/login.html">click here</a>.</p>
</body>
</html>