Test and fix ACL Editor

This commit is contained in:
zontreck 2024-07-02 17:57:40 -07:00
parent ae1da5f2b2
commit 5039722d90
2 changed files with 49 additions and 23 deletions

View file

@ -32,6 +32,7 @@ class MyApp extends StatelessWidget {
"/home": (context) => HomePage(settings: appSettings), "/home": (context) => HomePage(settings: appSettings),
"/creds": (context) => CredentialsPage(), "/creds": (context) => CredentialsPage(),
"/acl": (context) => AccessControlListPage(), "/acl": (context) => AccessControlListPage(),
"/acl/edit": (context) => ACLEdit(),
"/server": (context) => GameServerPage(settings: appSettings), "/server": (context) => GameServerPage(settings: appSettings),
"/server/autorestart": (context) => AutoRestartPage(), "/server/autorestart": (context) => AutoRestartPage(),
"/server/ports": (context) => ServerSettingsPage(), "/server/ports": (context) => ServerSettingsPage(),

View file

@ -21,9 +21,15 @@ class AccessControlState extends State<AccessControlListPage> {
backgroundColor: Constants.TITLEBAR_COLOR, backgroundColor: Constants.TITLEBAR_COLOR,
), ),
floatingActionButton: ElevatedButton( floatingActionButton: ElevatedButton(
onPressed: () { onPressed: () async {
// Show the add new user page // Show the add new user page
Navigator.pushNamed(context, "/acl/edit"); var reply = await Navigator.pushNamed(context, "/acl/edit");
if (reply == null) return;
if (reply is User) {
setState(() {
settings.inst!.admins.add(reply as User);
});
}
}, },
child: Icon(Icons.add), child: Icon(Icons.add),
), ),
@ -93,7 +99,8 @@ class ACLEditorState extends State<ACLEdit> {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text( title: Text(
"CE SM - ACL Edit - ${newUser ? "Create A User" : "Edit User - ${username.text}"}"), "CE SM - ACL Edit - ${newUser ? "Create A User" : "Edit User - ${username.text}"}",
),
backgroundColor: Constants.TITLEBAR_COLOR, backgroundColor: Constants.TITLEBAR_COLOR,
), ),
floatingActionButton: ElevatedButton( floatingActionButton: ElevatedButton(
@ -102,22 +109,30 @@ class ACLEditorState extends State<ACLEdit> {
if (!newUser) { if (!newUser) {
if (password.text.isEmpty) { if (password.text.isEmpty) {
user = User( user = User(
name: username.text, name: username.text,
passwordHash: current!.passwordHash, passwordHash: current!.passwordHash,
passwordSalt: current!.passwordSalt, passwordSalt: current!.passwordSalt,
permissions: current!.permissions, permissions: current!.permissions,
userHash: User.generateValidityCode( userHash: User.generateValidityCode(
username.text, username.text,
current!.passwordHash, current!.passwordHash,
current!.passwordSalt, current!.passwordSalt,
current!.permissions)); current!.permissions,
),
);
} else { } else {
user = User.make( user = User.make(
username.text, password.text, UserLevel.Administrator); username.text,
password.text,
UserLevel.Administrator,
);
} }
} else { } else {
user = User.make( user = User.make(
username.text, password.text, UserLevel.Administrator); username.text,
password.text,
UserLevel.Administrator,
);
} }
Navigator.pop(context, user); Navigator.pop(context, user);
@ -137,16 +152,20 @@ class ACLEditorState extends State<ACLEdit> {
title: Text("Username"), title: Text("Username"),
), ),
), ),
TextField( Expanded(
controller: username, child: TextField(
) controller: username,
),
),
], ],
), ),
if (!newUser) if (!newUser)
ListTile( ListTile(
title: Text("Warning"), title: Text("Warning"),
subtitle: Text( subtitle: Text(
"The password is encrypted, if you wish to change the password do so below, but the field is intentionally not filled in. If left blank, it will remain unchanged."), "The password is encrypted, if you wish to change the password do so below, but the field is intentionally not filled in. If left blank, it will remain unchanged.",
),
tileColor: Constants.TITLEBAR_COLOR,
), ),
Row( Row(
children: [ children: [
@ -156,21 +175,27 @@ class ACLEditorState extends State<ACLEdit> {
title: Text("Password"), title: Text("Password"),
), ),
), ),
TextField( Expanded(
controller: password, child: TextField(
obscureText: true, controller: password,
) obscureText: true,
),
),
], ],
), ),
SizedBox(
height: 50,
),
if (!newUser) if (!newUser)
ListTile( ListTile(
title: Text("DELETE USER"), title: Text("DELETE USER"),
leading: Icon(Icons.delete), leading: Icon(Icons.delete),
tileColor: Constants.TITLEBAR_COLOR,
subtitle: Text("Delete the current user entirely"), subtitle: Text("Delete the current user entirely"),
onTap: () { onTap: () {
Navigator.pop(context, false); Navigator.pop(context, false);
}, },
) ),
], ],
), ),
), ),