190 lines
7.5 KiB
Dart
190 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:footer/footer.dart';
|
|
import 'package:footer/footer_view.dart';
|
|
import 'package:libac_flutter/utils/Hashing.dart';
|
|
import 'package:zontreck/Constants.dart';
|
|
import 'package:zontreck/Packets.dart';
|
|
import 'package:zontreck/Settings.dart';
|
|
|
|
import '../LastNames.dart';
|
|
|
|
class RegisterAccountPage extends StatefulWidget {
|
|
const RegisterAccountPage({super.key});
|
|
|
|
@override
|
|
RegisterAccountState createState() => RegisterAccountState();
|
|
}
|
|
|
|
class RegisterAccountState extends State<RegisterAccountPage> {
|
|
RegisterAccountState();
|
|
|
|
Settings settings = Settings();
|
|
|
|
TextEditingController firstNameController = TextEditingController();
|
|
TextEditingController lastNameController = TextEditingController();
|
|
|
|
TextEditingController password = TextEditingController();
|
|
TextEditingController confirm = TextEditingController();
|
|
|
|
TextEditingController email = TextEditingController();
|
|
|
|
bool get passwordMatches =>
|
|
password.text == confirm.text &&
|
|
password.text != "" &&
|
|
confirm.text != "";
|
|
|
|
bool get canSubmit =>
|
|
firstNameController.text != "" &&
|
|
lastNameController.text != "" &&
|
|
passwordMatches &&
|
|
email.text != "";
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
lastNameController.text = settings.hasNoUsers ? "Piccari" : "";
|
|
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("OpenSim - Register Account"),
|
|
backgroundColor: Constants.TITLEBAR_COLOR,
|
|
),
|
|
floatingActionButton: canSubmit
|
|
? ElevatedButton(
|
|
onPressed: () async {
|
|
C2SRegisterAccountPacket packet = C2SRegisterAccountPacket(
|
|
firstName: firstNameController.text,
|
|
lastName: lastNameController.text,
|
|
passwordHash: Hashing.md5Hash(password.text),
|
|
email: email.text,
|
|
level: settings.hasNoUsers ? 240 : 1,
|
|
title: settings.hasNoUsers
|
|
? UserTitles.OPERATOR.title
|
|
: UserTitles.USER.title,
|
|
clientKey: Constants.CLIENTPSK,
|
|
);
|
|
|
|
var response = await settings.sendPacketToEndpoint(
|
|
APIEndpoint.Register, packet) as S2CSimpleReplyPacket;
|
|
|
|
if (response.done) {
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
content: Text(
|
|
"User Account Created. You must now login to finish setting up the account")));
|
|
Navigator.pop(context);
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
content:
|
|
Text("Fatal error when creating user account")));
|
|
}
|
|
},
|
|
child: const Text("Create my Account"))
|
|
: null,
|
|
body: FooterView(
|
|
footer: Footer(
|
|
alignment: Alignment.center,
|
|
backgroundColor: ThemeData.dark().focusColor,
|
|
child:
|
|
const Text("${Constants.COPYRIGHT}\n${Constants.VERSION}")),
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
settings.hasNoUsers
|
|
? ListTile(
|
|
title: const Text("There are no users on this grid."),
|
|
tileColor: Constants.TITLEBAR_COLOR,
|
|
subtitle: Text(
|
|
"This account will be granted Level 240, and the User Title : ${UserTitles.OPERATOR.title}"),
|
|
)
|
|
: const SizedBox(),
|
|
ListTile(
|
|
title: const Text("First Name"),
|
|
subtitle: TextField(
|
|
controller: firstNameController,
|
|
onChanged: (v) {
|
|
setState(() {});
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text("Last Name"),
|
|
subtitle: Constants.ALLOW_ANY_LAST_NAME ||
|
|
settings.hasNoUsers
|
|
? TextField(
|
|
controller: lastNameController,
|
|
onChanged: (v) {
|
|
setState(() {});
|
|
},
|
|
)
|
|
: DropdownMenu(
|
|
onSelected: (V) {
|
|
setState(() {
|
|
lastNameController.text = V as String;
|
|
});
|
|
},
|
|
dropdownMenuEntries:
|
|
LastNames.getCurrentNames(),
|
|
)),
|
|
ListTile(
|
|
title: const Text("Password"),
|
|
subtitle: TextField(
|
|
controller: password,
|
|
decoration: const InputDecoration(
|
|
hintText: "*******",
|
|
),
|
|
obscureText: true,
|
|
obscuringCharacter: "*",
|
|
onChanged: (V) {
|
|
setState(() {});
|
|
},
|
|
),
|
|
),
|
|
ListTile(
|
|
title: const Text("Password Confirmation"),
|
|
subtitle: TextField(
|
|
controller: confirm,
|
|
decoration: const InputDecoration(
|
|
hintText: "*******",
|
|
),
|
|
obscureText: true,
|
|
obscuringCharacter: "*",
|
|
onChanged: (V) {
|
|
setState(() {});
|
|
},
|
|
),
|
|
),
|
|
passwordMatches ||
|
|
password.text == "" && confirm.text == ""
|
|
? const Divider(
|
|
thickness: 2,
|
|
)
|
|
: const ListTile(
|
|
title: Text("Passwords do not match"),
|
|
tileColor: Constants.TITLEBAR_COLOR,
|
|
),
|
|
ListTile(
|
|
title: const Text("Email Address"),
|
|
subtitle: TextField(
|
|
onChanged: (V) {
|
|
setState(() {});
|
|
},
|
|
controller: email,
|
|
decoration: const InputDecoration(
|
|
hintText:
|
|
"Your email address. It is not used by zontreck.com, but if needed, can be used to reach you"),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]));
|
|
}
|
|
}
|