Clean up src
This commit is contained in:
parent
eba7e4b0b7
commit
eb9cbd9f66
@ -17,18 +17,8 @@ async function login(ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(user.value)
|
|
||||||
console.log(pass.value)
|
|
||||||
console.log(api_url)
|
|
||||||
console.log(payload)
|
|
||||||
console.log(fetch_options)
|
|
||||||
|
|
||||||
let resp = await fetch(api_url, fetch_options)
|
let resp = await fetch(api_url, fetch_options)
|
||||||
console.log(resp)
|
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
let ans = await resp.json()
|
|
||||||
console.log(ans)
|
|
||||||
|
|
||||||
window.location.hash = "/"
|
window.location.hash = "/"
|
||||||
} else {
|
} else {
|
||||||
user.value = ''
|
user.value = ''
|
||||||
@ -38,7 +28,6 @@ async function login(ev) {
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
let resp = await fetch("/api/user")
|
let resp = await fetch("/api/user")
|
||||||
console.log(resp)
|
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
window.location.hash = "/"
|
window.location.hash = "/"
|
||||||
}
|
}
|
||||||
@ -71,11 +60,6 @@ onMounted(async () => {
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
/* html,
|
|
||||||
body {
|
|
||||||
height: 100%;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.form-signin {
|
.form-signin {
|
||||||
max-width: 330px;
|
max-width: 330px;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
|
|||||||
@ -10,7 +10,6 @@ const err = ref('')
|
|||||||
|
|
||||||
async function signup(ev) {
|
async function signup(ev) {
|
||||||
ev.preventDefault()
|
ev.preventDefault()
|
||||||
console.log(ev)
|
|
||||||
const api_url = '/api/user'
|
const api_url = '/api/user'
|
||||||
const payload = { username: user.value, password: pass.value, referral: refe.value }
|
const payload = { username: user.value, password: pass.value, referral: refe.value }
|
||||||
const fetch_options = {
|
const fetch_options = {
|
||||||
@ -21,19 +20,10 @@ async function signup(ev) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(user.value)
|
|
||||||
console.log(pass.value)
|
|
||||||
console.log(api_url)
|
|
||||||
console.log(payload)
|
|
||||||
console.log(fetch_options)
|
|
||||||
|
|
||||||
let resp = await fetch(api_url, fetch_options)
|
let resp = await fetch(api_url, fetch_options)
|
||||||
console.log(resp)
|
|
||||||
if (resp.ok) {
|
if (resp.ok) {
|
||||||
err.value = ''
|
err.value = ''
|
||||||
let ans = await resp.json()
|
|
||||||
console.log(ans)
|
|
||||||
|
|
||||||
window.location.hash = "/"
|
window.location.hash = "/"
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
55
src/main.rs
55
src/main.rs
@ -22,57 +22,6 @@ use serde::{Deserialize, Serialize};
|
|||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use tokio::sync::broadcast::Sender;
|
use tokio::sync::broadcast::Sender;
|
||||||
|
|
||||||
#[handler]
|
|
||||||
fn index() -> Html<&'static str> {
|
|
||||||
Html(
|
|
||||||
r###"
|
|
||||||
<body>
|
|
||||||
<form id="loginForm">
|
|
||||||
Name: <input id="nameInput" type="text" />
|
|
||||||
<button type="submit">Login</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<form id="sendForm" hidden>
|
|
||||||
Text: <input id="msgInput" type="text" />
|
|
||||||
<button type="submit">Send</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<textarea id="msgsArea" cols="50" rows="30" hidden></textarea>
|
|
||||||
</body>
|
|
||||||
<script>
|
|
||||||
let ws;
|
|
||||||
const loginForm = document.querySelector("#loginForm");
|
|
||||||
const sendForm = document.querySelector("#sendForm");
|
|
||||||
const nameInput = document.querySelector("#nameInput");
|
|
||||||
const msgInput = document.querySelector("#msgInput");
|
|
||||||
const msgsArea = document.querySelector("#msgsArea");
|
|
||||||
|
|
||||||
nameInput.focus();
|
|
||||||
|
|
||||||
loginForm.addEventListener("submit", function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
loginForm.hidden = true;
|
|
||||||
sendForm.hidden = false;
|
|
||||||
msgsArea.hidden = false;
|
|
||||||
msgInput.focus();
|
|
||||||
let protocol = window.location.protocol == "https:" ? "wss://" : "ws://";
|
|
||||||
ws = new WebSocket(protocol + window.location.host + "/api/ws");
|
|
||||||
ws.onmessage = function(event) {
|
|
||||||
msgsArea.value += event.data + "\r\n";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
sendForm.addEventListener("submit", function(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
ws.send(msgInput.value);
|
|
||||||
msgInput.value = "";
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
"###,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Object, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Object, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
struct User {
|
struct User {
|
||||||
#[oai(validator(max_length = 64))]
|
#[oai(validator(max_length = 64))]
|
||||||
@ -277,9 +226,7 @@ impl Api {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[oai(path = "/num", method = "get", tag = "ApiTags::User")]
|
#[oai(path = "/num", method = "get", tag = "ApiTags::User")]
|
||||||
//async fn get_num(&self, session: &Session) -> Json<u32> {
|
|
||||||
async fn get_num(&self, session: &Session) -> NumResponse {
|
async fn get_num(&self, session: &Session) -> NumResponse {
|
||||||
//if session.get("user")
|
|
||||||
if let None = session.get::<String>("user") {
|
if let None = session.get::<String>("user") {
|
||||||
return NumResponse::AuthError;
|
return NumResponse::AuthError;
|
||||||
}
|
}
|
||||||
@ -314,7 +261,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let channel = tokio::sync::broadcast::channel::<String>(128).0;
|
let channel = tokio::sync::broadcast::channel::<String>(128).0;
|
||||||
|
|
||||||
//let dbpool = SqlitePool::connect("sqlite:chat.db").await?;
|
|
||||||
let dbpool = Pool::<Sqlite>::connect("sqlite:chat.db").await?;
|
let dbpool = Pool::<Sqlite>::connect("sqlite:chat.db").await?;
|
||||||
let api = OpenApiService::new(
|
let api = OpenApiService::new(
|
||||||
Api {
|
Api {
|
||||||
@ -328,7 +274,6 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
let static_endpoint = StaticFilesEndpoint::new("./client/dist").index_file("index.html");
|
let static_endpoint = StaticFilesEndpoint::new("./client/dist").index_file("index.html");
|
||||||
|
|
||||||
let app = Route::new()
|
let app = Route::new()
|
||||||
.at("/api/test", get(index))
|
|
||||||
.nest("/", static_endpoint)
|
.nest("/", static_endpoint)
|
||||||
.nest("/api", api)
|
.nest("/api", api)
|
||||||
.with(session);
|
.with(session);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user