210 lines
6 KiB
Dart
210 lines
6 KiB
Dart
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: () async {
|
|
// Show the add new user page
|
|
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),
|
|
),
|
|
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();
|
|
var canDelete = true;
|
|
|
|
User? current;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
var args = ModalRoute.of(context)!.settings.arguments;
|
|
if (args == null) {
|
|
newUser = true;
|
|
canDelete = false;
|
|
} else {
|
|
User usr = args as User;
|
|
|
|
username.text = usr.name;
|
|
current = usr;
|
|
canDelete = true;
|
|
|
|
if (usr.permissions == UserLevel.Super_User) canDelete = false;
|
|
}
|
|
|
|
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"),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: 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.",
|
|
),
|
|
tileColor: Constants.TITLEBAR_COLOR,
|
|
),
|
|
Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 150,
|
|
child: ListTile(
|
|
title: Text("Password"),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: TextField(
|
|
controller: password,
|
|
obscureText: true,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(
|
|
height: 50,
|
|
),
|
|
if (canDelete)
|
|
ListTile(
|
|
title: Text("DELETE USER"),
|
|
leading: Icon(Icons.delete),
|
|
tileColor: Constants.TITLEBAR_COLOR,
|
|
subtitle: Text("Delete the current user entirely"),
|
|
onTap: () {
|
|
Navigator.pop(context, false);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|