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'; class RegisterAccountPage extends StatefulWidget { RegisterAccountPage({super.key}); @override RegisterAccountState createState() => RegisterAccountState(); } class RegisterAccountState extends State { 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: 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(SnackBar( content: Text( "User Account Created. You must now login to finish setting up the account"))); Navigator.pop(context); } else { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text("Fatal error when creating user account"))); } }, child: 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: EdgeInsets.all(8), child: SingleChildScrollView( child: Column( children: [ settings.hasNoUsers ? ListTile( title: 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}"), ) : SizedBox(), ListTile( title: Text("First Name"), subtitle: TextField( controller: firstNameController, onChanged: (v) { setState(() {}); }, ), ), ListTile( title: 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: Text("Password"), subtitle: TextField( controller: password, decoration: InputDecoration( hintText: "*******", ), obscureText: true, obscuringCharacter: "*", onChanged: (V) { setState(() {}); }, ), ), ListTile( title: Text("Password Confirmation"), subtitle: TextField( controller: confirm, decoration: InputDecoration( hintText: "*******", ), obscureText: true, obscuringCharacter: "*", onChanged: (V) { setState(() {}); }, ), ), passwordMatches || password.text == "" && confirm.text == "" ? Divider( thickness: 2, ) : ListTile( title: Text("Passwords do not match"), tileColor: Constants.TITLEBAR_COLOR, ), ListTile( title: Text("Email Address"), subtitle: TextField( onChanged: (V) { setState(() {}); }, controller: email, decoration: InputDecoration( hintText: "Your email address. It is not used by zontreck.com, but if needed, can be used to reach you"), ), ) ], ), ), ), ])); } } enum LastNames { Aabye, Aarde, Bailey, Caballero; static List> getCurrentNames() { return [ LastNames.Aabye.getEntry(), LastNames.Aarde.getEntry(), LastNames.Bailey.getEntry(), LastNames.Caballero.getEntry() ]; } DropdownMenuEntry getEntry() { return DropdownMenuEntry(value: this.name, label: this.name); } }