Start implementing screens for registering and logging in
This commit is contained in:
parent
7ecfd336f6
commit
486318acac
5 changed files with 90 additions and 10 deletions
|
@ -7,7 +7,7 @@ class Constants {
|
|||
static const TITLEBAR_COLOR = Color.fromARGB(255, 97, 0, 0);
|
||||
static const DRAWER_COLOR = Color.fromARGB(148, 0, 97, 97);
|
||||
|
||||
static const VERSION = "1.0.051524.1602";
|
||||
static const VERSION = "1.0.051524.1622";
|
||||
static const COPYRIGHT = "Copyright 2024 - Tara Piccari. All rights Reserved";
|
||||
static const CLIENTPSK =
|
||||
"f5c6caf3efe1ec5aa4b7c572f92aa14782b7be34b4c7844fa9c6d47fdf94246";
|
||||
|
|
|
@ -89,13 +89,30 @@ class C2SPerformSetupPacket implements IPacket {
|
|||
class S2CPongPacket implements IPacket {
|
||||
final String PSK;
|
||||
final bool authorized;
|
||||
final String user;
|
||||
final String displayName;
|
||||
final bool loggedIn;
|
||||
final int totalUsers;
|
||||
|
||||
S2CPongPacket({required this.PSK, required this.authorized});
|
||||
S2CPongPacket(
|
||||
{required this.PSK,
|
||||
required this.authorized,
|
||||
required this.user,
|
||||
required this.displayName,
|
||||
required this.loggedIn,
|
||||
required this.totalUsers});
|
||||
|
||||
@override
|
||||
String encode() {
|
||||
return json
|
||||
.encode({"psk": PSK, "autorized": authorized, "type": getType()});
|
||||
return json.encode({
|
||||
"psk": PSK,
|
||||
"authorized": authorized,
|
||||
"type": getType(),
|
||||
"login": loggedIn,
|
||||
"user": user,
|
||||
"display_name": displayName,
|
||||
"user_count": totalUsers
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -112,7 +129,12 @@ class S2CPongPacket implements IPacket {
|
|||
var map = json.decode(params);
|
||||
|
||||
return S2CPongPacket(
|
||||
PSK: map['psk'] as String, authorized: map['authorized'] as bool);
|
||||
PSK: map['psk'] as String,
|
||||
authorized: map['authorized'] as bool,
|
||||
user: map['user'] as String,
|
||||
displayName: map['display_name'] as String,
|
||||
loggedIn: map['login'] as bool,
|
||||
totalUsers: map['user_count'] as int);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,11 @@ class Settings {
|
|||
String PSK =
|
||||
""; // This is not saved anywhere it is discarded when the application is unloaded.
|
||||
|
||||
bool loggedIn = false;
|
||||
String userName = "";
|
||||
String displayName = "";
|
||||
int totalGridUsers = 0;
|
||||
|
||||
void setServices(Map<String, dynamic> js) {
|
||||
var protocol = js['api']['protocol'] as String;
|
||||
var port = js['api']['port'] as int;
|
||||
|
|
|
@ -34,8 +34,13 @@ class OpenSimPageState extends State<OpenSimPage> {
|
|||
settings.OpenSimSetupCompleted = false;
|
||||
}
|
||||
|
||||
var pong =
|
||||
await settings.sendPacketToEndpoint(APIEndpoint.Ping, NullPacket());
|
||||
var pong = await settings.sendPacketToEndpoint(
|
||||
APIEndpoint.Ping, NullPacket()) as S2CPongPacket;
|
||||
|
||||
settings.loggedIn = pong.loggedIn;
|
||||
settings.userName = pong.user;
|
||||
settings.displayName = pong.displayName;
|
||||
settings.totalGridUsers = pong.totalUsers;
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
@ -58,8 +63,32 @@ class OpenSimPageState extends State<OpenSimPage> {
|
|||
padding: const EdgeInsets.all(8),
|
||||
child: SingleChildScrollView(
|
||||
child: settings.OpenSimSetupCompleted
|
||||
? const Column(
|
||||
children: [],
|
||||
? Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(
|
||||
"There are ${settings.totalGridUsers} users registered with this grid",
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text(settings.loggedIn
|
||||
? "Welcome, ${settings.displayName}"
|
||||
: "You are not currently logged in"),
|
||||
),
|
||||
settings.loggedIn
|
||||
? SizedBox()
|
||||
: Center(
|
||||
child: Row(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {}, child: Text("Login")),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
child: Text("Register Account"))
|
||||
],
|
||||
))
|
||||
],
|
||||
)
|
||||
: Column(
|
||||
children: [
|
||||
|
@ -145,6 +174,8 @@ class OpenSimPageState extends State<OpenSimPage> {
|
|||
settings.OpenSimSetupCompleted = false;
|
||||
}
|
||||
|
||||
didChangeDependencies();
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
child: const Text("Submit"))
|
||||
|
|
24
php/Ping.php
24
php/Ping.php
|
@ -7,6 +7,11 @@ $js = getJsonizedInput();
|
|||
$psk = "";
|
||||
$allow=false;
|
||||
|
||||
$user = "";
|
||||
$display_name = "";
|
||||
$logged_in = false;
|
||||
$totalUsers = 0;
|
||||
|
||||
if(!defined("CLIENTPSK")) {
|
||||
$allow=true;
|
||||
} else {
|
||||
|
@ -15,16 +20,33 @@ if(!defined("CLIENTPSK")) {
|
|||
// Authorized. Send the PSK value to the client
|
||||
$allow=true;
|
||||
$psk = PSK;
|
||||
|
||||
// Check session
|
||||
if(isset($_SESSION['login'])) {
|
||||
$logged_in = true;
|
||||
$user = $_SESSION['user'];
|
||||
$display_name = $_SESSION['display_name'];
|
||||
}
|
||||
}else {
|
||||
$allow=false;
|
||||
}
|
||||
|
||||
$DB = get_DB();
|
||||
// Query total number of users
|
||||
$res = $DB->query("SELECT * FROM auth;");
|
||||
$totalUsers = $res->num_rows;
|
||||
|
||||
$DB->close();
|
||||
}
|
||||
|
||||
$ret = array(
|
||||
"type" => "S2CPong",
|
||||
"authorized" => $allow,
|
||||
"psk" => $psk
|
||||
"user" => $user,
|
||||
"display_name" => $display_name,
|
||||
"psk" => $psk,
|
||||
"login" => $logged_in,
|
||||
"user_count" => $totalUsers
|
||||
);
|
||||
|
||||
die(json_encode($ret));
|
||||
|
|
Loading…
Reference in a new issue