pub struct InitialAdminSetup {
_marker: PhantomData<()>,
function_component: FunctionComponent<Self>,
}Expand description
Component for the initial admin account setup page.
This page is displayed when a fresh system has no administrator accounts. It provides a form to create the first admin user. Key functionality:
- Admin Check: On mount, verifies if an admin already exists by calling
/api/check-admin. If an admin is found, the user is redirected to the login page (crate::Route::Login). - Form Fields: Collects
first_name,last_name,username,password, andconfirm_password. - Form Validation:
- Ensures password fields are not empty.
- Verifies that
passwordandconfirm_passwordmatch. - Ensures the
usernamefield is not empty.
- API Interaction: On form submission, a POST request is sent to
/api/setup-adminwith the new admin’s details. - Password Hashing: The backend is responsible for hashing the password using Argon2 before storage; this component only sends the plain text password.
- Auto-redirect: On successful admin account creation, the user is automatically
redirected to the login page (
crate::Route::Login). - State Management: Uses Yew’s
use_statehooks to manage:- Input field values (
first_name,last_name,username,pwd,pwd_confirm). - UI states like
errormessages,successstatus, andloadingindicators. admin_check_doneto prevent rendering the form before the initial admin check completes.
- Input field values (
§Example Flow
- User navigates to
/setup. - The component checks
/api/check-admin. - If an admin exists, redirects to
/login. - If no admin exists, the setup form is displayed.
- User fills out the form and submits.
- Form data is sent via POST to
/api/setup-admin. - On successful response (HTTP 200), redirects to
/login. - On error, displays an error message to the user.
§Security Notes
- The initial admin check prevents re-creating an admin if one already exists.
- Password confirmation helps prevent user typos for critical credentials.
- Backend validation further ensures non-empty and secure credentials.
Fields§
§_marker: PhantomData<()>§function_component: FunctionComponent<Self>Trait Implementations§
Source§impl BaseComponent for InitialAdminSetupwhere
Self: 'static,
impl BaseComponent for InitialAdminSetupwhere
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.
Source§impl Debug for InitialAdminSetup
impl Debug for InitialAdminSetup
Auto Trait Implementations§
impl !Freeze for InitialAdminSetup
impl !RefUnwindSafe for InitialAdminSetup
impl !Send for InitialAdminSetup
impl !Sync for InitialAdminSetup
impl Unpin for InitialAdminSetup
impl !UnwindSafe for InitialAdminSetup
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.