WIP: Authd Admin: Search User Interface.

beta
Philippe Pittoli 2024-02-17 02:22:40 +01:00
parent 554280956b
commit ef22dd22c3
1 changed files with 72 additions and 32 deletions

View File

@ -3,6 +3,7 @@
- TODO: add, remove, search, validate users - TODO: add, remove, search, validate users
- TODO: raise a user to admin - TODO: raise a user to admin
- TODO: list users (getting them slowly, otherwise it will cause problems with thousands of logins) - TODO: list users (getting them slowly, otherwise it will cause problems with thousands of logins)
Is this page should be used to provide `dnsmanager` administration?
-} -}
module App.AuthenticationDaemonAdminInterface where module App.AuthenticationDaemonAdminInterface where
@ -45,25 +46,37 @@ type Slot = H.Slot Query Output
type Input = Unit type Input = Unit
data AddUserInput data AddUserInput
= ADDUSER_INP_login String = ADDUSER_INP_login String
| ADDUSER_INP_email String | ADDUSER_INP_email String
| ADDUSER_toggle_admin | ADDUSER_toggle_admin
| ADDUSER_INP_pass String | ADDUSER_INP_pass String
| SEARCHUSER_INP_login String
| SEARCHUSER_INP_email String
| SEARCHUSER_toggle_admin
--| SEARCHUSER_INP_domain
data Action data Action
= HandleAddUserInput AddUserInput = HandleAddUserInput AddUserInput
| AddUserAttempt | AddUserAttempt
| SearchUserAttempt
| PreventSubmit Event | PreventSubmit Event
| Initialize | Initialize
| Finalize | Finalize
-- | There are different `sub-pages` in the authentication daemon admin page.
-- | For example, users can be searched and a list is provided.
data Page = Home | SearchUser | AddUser
type StateAddUserForm = { login :: String, admin :: Boolean, email :: String, pass :: String } type StateAddUserForm = { login :: String, admin :: Boolean, email :: String, pass :: String }
type StateSearchUserForm = { login :: String, admin :: Boolean, email :: String, domain :: String }
type State = type State =
{ addUserForm :: StateAddUserForm { addUserForm :: StateAddUserForm
, wsUp :: Boolean , searchUserForm :: StateSearchUserForm
, page :: Page
, wsUp :: Boolean
} }
component :: forall m. MonadAff m => H.Component Query Input Output m component :: forall m. MonadAff m => H.Component Query Input Output m
@ -80,39 +93,29 @@ component =
} }
initialState :: Input -> State initialState :: Input -> State
initialState _ = { addUserForm: { login: "", admin: false, email: "", pass: "" }, wsUp: true } initialState _ = { addUserForm: { login: "", admin: false, email: "", pass: "" }
, searchUserForm: { login: "", admin: false, email: "", domain: "" }
, page: Home
, wsUp: true
}
render :: forall m. State -> H.ComponentHTML Action () m render :: forall m. State -> H.ComponentHTML Action () m
render { addUserForm, wsUp } render { addUserForm, searchUserForm, page, wsUp }
= HH.div_ = case page of
[ Bulma.columns_ [ Bulma.column_ adduser_form ] Home -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
] SearchUser -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Search users", render_searchuser_form ] ]
, Bulma.column_ [ Bulma.h3 "Result", Bulma.subtitle "TODO" ] ]
AddUser -> HH.div_ [ Bulma.columns_ [ Bulma.column_ [ Bulma.h3 "Add a new user", render_adduser_form ] ] ]
where where
adduser_form active = (if wsUp then (HP.enabled true) else (HP.disabled true))
= [ Bulma.h3 "Add a new user"
, render_adduser_form
]
should_be_disabled = (if wsUp then (HP.enabled true) else (HP.disabled true))
render_adduser_form = HH.form render_adduser_form = HH.form
[ HE.onSubmit PreventSubmit ] [ HE.onSubmit PreventSubmit ]
[ Bulma.box_input "login" "User login" "login" -- title, placeholder [ Bulma.box_input "login" "User login" "login" (up ADDUSER_INP_login) addUserForm.login active
(HandleAddUserInput <<< ADDUSER_INP_login) -- action , Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
addUserForm.login -- value , Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active
should_be_disabled -- condition , Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
, Bulma.btn
(show addUserForm.admin) -- value
(HandleAddUserInput ADDUSER_toggle_admin) -- action
, Bulma.box_input "email" "User email" "email" -- title, placeholder
(HandleAddUserInput <<< ADDUSER_INP_email) -- action
addUserForm.email -- value
should_be_disabled -- condition
, Bulma.box_password "password" "User password" "password" -- title, placeholder
(HandleAddUserInput <<< ADDUSER_INP_pass) -- action
addUserForm.pass -- value
should_be_disabled -- condition
, HH.button , HH.button
[ HP.style "padding: 0.5rem 1.25rem;" [ HP.style "padding: 0.5rem 1.25rem;"
, HP.type_ HP.ButtonSubmit , HP.type_ HP.ButtonSubmit
@ -121,6 +124,23 @@ render { addUserForm, wsUp }
] ]
[ HH.text "Send Message to Server" ] [ HH.text "Send Message to Server" ]
] ]
up x = HandleAddUserInput <<< x
render_searchuser_form = HH.form
[ HE.onSubmit PreventSubmit ]
[ Bulma.box_input "login" "User login" "login" (up SEARCHUSER_INP_login) searchUserForm.login active
, Bulma.btn (show searchUserForm.admin) (HandleAddUserInput SEARCHUSER_toggle_admin)
, Bulma.box_input "email" "User email" "email" (up SEARCHUSER_INP_email) searchUserForm.email active
--, Bulma.box_input "domain" "Domain owned" "blah.netlib.re."
-- (up SEARCHUSER_INP_domain) searchUserForm.email active
, HH.button
[ HP.style "padding: 0.5rem 1.25rem;"
, HP.type_ HP.ButtonSubmit
, HE.onClick \ _ -> SearchUserAttempt
, (if wsUp then (HP.enabled true) else (HP.disabled true))
]
[ HH.text "Send Message to Server" ]
]
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
handleAction = case _ of handleAction = case _ of
@ -132,12 +152,16 @@ handleAction = case _ of
H.raise $ StoreState state H.raise $ StoreState state
HandleAddUserInput adduserinp -> do HandleAddUserInput adduserinp -> do
{ addUserForm } <- H.get { addUserForm, searchUserForm } <- H.get
case adduserinp of case adduserinp of
ADDUSER_INP_login v -> H.modify_ _ { addUserForm { login = v } } ADDUSER_INP_login v -> H.modify_ _ { addUserForm { login = v } }
ADDUSER_INP_email v -> H.modify_ _ { addUserForm { email = v } } ADDUSER_INP_email v -> H.modify_ _ { addUserForm { email = v } }
ADDUSER_toggle_admin -> H.modify_ _ { addUserForm { admin = not addUserForm.admin } } ADDUSER_toggle_admin -> H.modify_ _ { addUserForm { admin = not addUserForm.admin } }
ADDUSER_INP_pass v -> H.modify_ _ { addUserForm { pass = v } } ADDUSER_INP_pass v -> H.modify_ _ { addUserForm { pass = v } }
SEARCHUSER_INP_login v -> H.modify_ _ { searchUserForm { login = v } }
SEARCHUSER_INP_email v -> H.modify_ _ { searchUserForm { email = v } }
SEARCHUSER_toggle_admin -> H.modify_ _ { searchUserForm { admin = not searchUserForm.admin } }
-- SEARCHUSER_INP_domain v -> H.modify_ _ { searchUserForm { domain = v } }
PreventSubmit ev -> H.liftEffect $ Event.preventDefault ev PreventSubmit ev -> H.liftEffect $ Event.preventDefault ev
@ -165,6 +189,22 @@ handleAction = case _ of
H.raise $ MessageToSend ab H.raise $ MessageToSend ab
H.raise $ Log $ SimpleLog "[😇] Trying to add a user" H.raise $ Log $ SimpleLog "[😇] Trying to add a user"
SearchUserAttempt -> do
{ searchUserForm } <- H.get
let login = searchUserForm.login
email = searchUserForm.email
-- domain = searchUserForm.domain
admin = searchUserForm.admin
--ab <- H.liftEffect $ AuthD.serialize $ AuthD.MkSearchUser { login:
-- , admin:
-- , email: Just (Email.Email email)
-- , domain:
-- }
--H.raise $ MessageToSend ab
H.raise $ Log $ SimpleLog "[😇] TODO: Trying to add a user"
handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a) handleQuery :: forall a m. MonadAff m => Query a -> H.HalogenM State Action () Output m (Maybe a)
handleQuery = case _ of handleQuery = case _ of