kitchen/web/src/pages/login.rs

55 lines
2.2 KiB
Rust
Raw Normal View History

2022-08-30 17:31:33 -04:00
// Copyright 2022 Jeremy Wall (Jeremy@marzhilsltudios.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use sycamore::futures::spawn_local_scoped;
use sycamore::prelude::*;
use tracing::{debug, info};
2022-08-30 17:31:33 -04:00
2022-12-27 23:00:48 -05:00
use crate::app_state::{Message, StateHandler};
2022-08-30 17:31:33 -04:00
#[component]
2022-12-27 23:00:48 -05:00
pub fn LoginForm<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
let username = create_signal(cx, "".to_owned());
let password = create_signal(cx, "".to_owned());
view! {cx,
2022-08-30 17:31:33 -04:00
form() {
label(for="username") { "Username" }
input(type="text", id="username", bind:value=username)
2022-08-30 17:31:33 -04:00
label(for="password") { "Password" }
input(type="password", bind:value=password)
input(type="button", value="Login", on:click=move |_| {
2022-08-30 17:31:33 -04:00
info!("Attempting login request");
let (username, password) = ((*username.get_untracked()).clone(), (*password.get_untracked()).clone());
if username != "" && password != "" {
spawn_local_scoped(cx, async move {
let store = crate::api::HttpStore::get_from_context(cx);
debug!("authenticating against ui");
// TODO(jwall): Navigate to plan if the below is successful.
if let Some(user_data) = store.authenticate(username, password).await {
sh.dispatch(cx, Message::SetUserData(user_data));
}
});
}
2022-08-30 17:31:33 -04:00
debug!("triggering login click subscribers");
}) { }
2022-08-30 17:31:33 -04:00
}
}
}
#[component]
pub fn LoginPage<'ctx, G: Html>(cx: Scope<'ctx>, sh: StateHandler<'ctx>) -> View<G> {
view! {cx,
2022-12-27 23:00:48 -05:00
LoginForm(sh)
2022-08-30 17:31:33 -04:00
}
}