Adds a full access control list editor
This commit is contained in:
parent
4b71526270
commit
ae1da5f2b2
6 changed files with 201 additions and 6 deletions
180
lib/pages/ACL.dart
Normal file
180
lib/pages/ACL.dart
Normal file
|
@ -0,0 +1,180 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:servermanager/pages/Constants.dart';
|
||||
import 'package:servermanager/structs/credentials.dart';
|
||||
import 'package:servermanager/structs/settings.dart';
|
||||
|
||||
class AccessControlListPage extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return AccessControlState();
|
||||
}
|
||||
}
|
||||
|
||||
class AccessControlState extends State<AccessControlListPage> {
|
||||
Settings settings = Settings();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Conan Exiles Server Manager - ACL Editor"),
|
||||
backgroundColor: Constants.TITLEBAR_COLOR,
|
||||
),
|
||||
floatingActionButton: ElevatedButton(
|
||||
onPressed: () {
|
||||
// Show the add new user page
|
||||
Navigator.pushNamed(context, "/acl/edit");
|
||||
},
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: ListView.builder(
|
||||
itemBuilder: (ctx, index) {
|
||||
User user = settings.inst!.admins[index];
|
||||
return ListTile(
|
||||
title: Text(user.name),
|
||||
subtitle: Text("Access Level: ${user.permissions.name}"),
|
||||
onTap: () async {
|
||||
var edited = await Navigator.pushNamed(context, "/acl/edit",
|
||||
arguments: user);
|
||||
if (edited == null) return;
|
||||
|
||||
if (edited is bool) {
|
||||
settings.inst!.admins.remove(user);
|
||||
setState(() {});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
settings.inst!.admins[index] = edited as User;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
itemCount: settings.inst!.admins.length,
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ACLEdit extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return ACLEditorState();
|
||||
}
|
||||
}
|
||||
|
||||
class ACLEditorState extends State<ACLEdit> {
|
||||
Settings settings = Settings();
|
||||
var newUser = false;
|
||||
TextEditingController username = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
|
||||
User? current;
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
var args = ModalRoute.of(context)!.settings.arguments;
|
||||
if (args == null) {
|
||||
newUser = true;
|
||||
} else {
|
||||
User usr = args as User;
|
||||
|
||||
username.text = usr.name;
|
||||
current = usr;
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
"CE SM - ACL Edit - ${newUser ? "Create A User" : "Edit User - ${username.text}"}"),
|
||||
backgroundColor: Constants.TITLEBAR_COLOR,
|
||||
),
|
||||
floatingActionButton: ElevatedButton(
|
||||
onPressed: () {
|
||||
User? user;
|
||||
if (!newUser) {
|
||||
if (password.text.isEmpty) {
|
||||
user = User(
|
||||
name: username.text,
|
||||
passwordHash: current!.passwordHash,
|
||||
passwordSalt: current!.passwordSalt,
|
||||
permissions: current!.permissions,
|
||||
userHash: User.generateValidityCode(
|
||||
username.text,
|
||||
current!.passwordHash,
|
||||
current!.passwordSalt,
|
||||
current!.permissions));
|
||||
} else {
|
||||
user = User.make(
|
||||
username.text, password.text, UserLevel.Administrator);
|
||||
}
|
||||
} else {
|
||||
user = User.make(
|
||||
username.text, password.text, UserLevel.Administrator);
|
||||
}
|
||||
|
||||
Navigator.pop(context, user);
|
||||
},
|
||||
child: Text("Save"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: ListTile(
|
||||
title: Text("Username"),
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: username,
|
||||
)
|
||||
],
|
||||
),
|
||||
if (!newUser)
|
||||
ListTile(
|
||||
title: Text("Warning"),
|
||||
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."),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: ListTile(
|
||||
title: Text("Password"),
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: password,
|
||||
obscureText: true,
|
||||
)
|
||||
],
|
||||
),
|
||||
if (!newUser)
|
||||
ListTile(
|
||||
title: Text("DELETE USER"),
|
||||
leading: Icon(Icons.delete),
|
||||
subtitle: Text("Delete the current user entirely"),
|
||||
onTap: () {
|
||||
Navigator.pop(context, false);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue