WIP: Authd Admin: Search User Interface.
This commit is contained in:
parent
554280956b
commit
ef22dd22c3
@ -3,6 +3,7 @@
|
||||
- TODO: add, remove, search, validate users
|
||||
- TODO: raise a user to admin
|
||||
- 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
|
||||
|
||||
@ -45,25 +46,37 @@ type Slot = H.Slot Query Output
|
||||
type Input = Unit
|
||||
|
||||
data AddUserInput
|
||||
= ADDUSER_INP_login String
|
||||
| ADDUSER_INP_email String
|
||||
= ADDUSER_INP_login String
|
||||
| ADDUSER_INP_email String
|
||||
| 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
|
||||
= HandleAddUserInput AddUserInput
|
||||
|
||||
| AddUserAttempt
|
||||
| SearchUserAttempt
|
||||
| PreventSubmit Event
|
||||
|
||||
| Initialize
|
||||
| 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 StateSearchUserForm = { login :: String, admin :: Boolean, email :: String, domain :: String }
|
||||
|
||||
type State =
|
||||
{ addUserForm :: StateAddUserForm
|
||||
, wsUp :: Boolean
|
||||
{ addUserForm :: StateAddUserForm
|
||||
, searchUserForm :: StateSearchUserForm
|
||||
, page :: Page
|
||||
, wsUp :: Boolean
|
||||
}
|
||||
|
||||
component :: forall m. MonadAff m => H.Component Query Input Output m
|
||||
@ -80,39 +93,29 @@ component =
|
||||
}
|
||||
|
||||
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 { addUserForm, wsUp }
|
||||
= HH.div_
|
||||
[ Bulma.columns_ [ Bulma.column_ adduser_form ]
|
||||
]
|
||||
render { addUserForm, searchUserForm, page, wsUp }
|
||||
= case page of
|
||||
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
|
||||
|
||||
adduser_form
|
||||
= [ Bulma.h3 "Add a new user"
|
||||
, render_adduser_form
|
||||
]
|
||||
|
||||
should_be_disabled = (if wsUp then (HP.enabled true) else (HP.disabled true))
|
||||
active = (if wsUp then (HP.enabled true) else (HP.disabled true))
|
||||
|
||||
render_adduser_form = HH.form
|
||||
[ HE.onSubmit PreventSubmit ]
|
||||
[ Bulma.box_input "login" "User login" "login" -- title, placeholder
|
||||
(HandleAddUserInput <<< ADDUSER_INP_login) -- action
|
||||
addUserForm.login -- value
|
||||
should_be_disabled -- condition
|
||||
, 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
|
||||
[ Bulma.box_input "login" "User login" "login" (up ADDUSER_INP_login) addUserForm.login active
|
||||
, Bulma.btn (show addUserForm.admin) (HandleAddUserInput ADDUSER_toggle_admin)
|
||||
, Bulma.box_input "email" "User email" "email" (up ADDUSER_INP_email) addUserForm.email active
|
||||
, Bulma.box_password "password" "User password" "password" (up ADDUSER_INP_pass) addUserForm.pass active
|
||||
, HH.button
|
||||
[ HP.style "padding: 0.5rem 1.25rem;"
|
||||
, HP.type_ HP.ButtonSubmit
|
||||
@ -121,6 +124,23 @@ render { addUserForm, wsUp }
|
||||
]
|
||||
[ 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 = case _ of
|
||||
@ -132,12 +152,16 @@ handleAction = case _ of
|
||||
H.raise $ StoreState state
|
||||
|
||||
HandleAddUserInput adduserinp -> do
|
||||
{ addUserForm } <- H.get
|
||||
{ addUserForm, searchUserForm } <- H.get
|
||||
case adduserinp of
|
||||
ADDUSER_INP_login v -> H.modify_ _ { addUserForm { login = v } }
|
||||
ADDUSER_INP_email v -> H.modify_ _ { addUserForm { email = v } }
|
||||
ADDUSER_toggle_admin -> H.modify_ _ { addUserForm { admin = not addUserForm.admin } }
|
||||
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
|
||||
|
||||
@ -165,6 +189,22 @@ handleAction = case _ of
|
||||
H.raise $ MessageToSend ab
|
||||
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 = case _ of
|
||||
|
Loading…
Reference in New Issue
Block a user