pub struct Login {
_marker: PhantomData<()>,
function_component: FunctionComponent<Self>,
}Expand description
A component providing a form for user login.
This component handles user authentication by collecting a username and password,
then sending these credentials to the backend /api/login endpoint. It manages
UI states for loading, errors, and success, and redirects to the home page on successful login.
§State
Uses use_state hooks to manage:
username,pwd: Values of the login form input fields.loading: A boolean to indicate if the login process is ongoing.error: A string to display any login error messages.success: A boolean to indicate if login was successful.
§Form Submission
- Prevents default form submission behavior.
- Constructs a
LoginSchemepayload from the input fields. - Sends a POST request to
/api/login. - On successful response (HTTP 200), sets
successto true and redirects tocrate::Route::Home. - On error, updates the
errorstate with the appropriate message.
§Example
html! {
<Login />
}Fields§
§_marker: PhantomData<()>§function_component: FunctionComponent<Self>Trait Implementations§
Source§impl BaseComponent for Loginwhere
Self: 'static,
impl BaseComponent for Loginwhere
Self: 'static,
Source§type Properties = ()
type Properties = ()
The Component’s Properties.
Source§fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool
fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool
Updates component’s internal state.
Source§fn changed(
&mut self,
_ctx: &Context<Self>,
_old_props: &Self::Properties,
) -> bool
fn changed( &mut self, _ctx: &Context<Self>, _old_props: &Self::Properties, ) -> bool
React to changes of component properties.
Source§fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool)
fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool)
Notified after a layout is rendered.
Source§fn prepare_state(&self) -> Option<String>
fn prepare_state(&self) -> Option<String>
Prepares the server-side state.
Auto Trait Implementations§
impl !Freeze for Login
impl !RefUnwindSafe for Login
impl !Send for Login
impl !Sync for Login
impl Unpin for Login
impl !UnwindSafe for Login
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
Convert
self to a value of a Properties struct.§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
Convert
self to a value of a Properties struct.