Fix a typo
This commit is contained in:
parent
ad4b7fc4e7
commit
a0f0e95043
6 changed files with 118 additions and 37 deletions
|
@ -306,6 +306,6 @@ class S2CLoginResponsePacket implements IPacket {
|
|||
return S2CLoginResponsePacket(
|
||||
loggedIn: map['login'] as bool,
|
||||
reason: map['reason'] as String,
|
||||
user: User.parseJson(json.encode(map['user'])));
|
||||
user: User.parseJson(map['user']));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
|
|||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_flutter/utils/Hashing.dart';
|
||||
import 'package:zontreck/Packets.dart';
|
||||
import 'package:zontreck/pages/OpenSim.dart';
|
||||
|
||||
enum APIEndpoint {
|
||||
SetupCheck(script: "SetupCheck.php", path: "/ac/home/supports/"),
|
||||
|
@ -66,6 +67,8 @@ class Settings {
|
|||
String displayName = "";
|
||||
int totalGridUsers = 0;
|
||||
|
||||
late User currentUser;
|
||||
|
||||
bool get hasUsers => totalGridUsers != 0;
|
||||
bool get hasNoUsers => totalGridUsers == 0;
|
||||
|
||||
|
|
81
lib/pages/LoginAccount.dart
Normal file
81
lib/pages/LoginAccount.dart
Normal file
|
@ -0,0 +1,81 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:zontreck/Constants.dart';
|
||||
import 'package:zontreck/Packets.dart';
|
||||
import 'package:zontreck/Settings.dart';
|
||||
|
||||
class LoginAccountPage extends StatefulWidget {
|
||||
LoginAccountPage({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => LoginAccountState();
|
||||
}
|
||||
|
||||
class LoginAccountState extends State<LoginAccountPage> {
|
||||
TextEditingController first = TextEditingController();
|
||||
TextEditingController last = TextEditingController();
|
||||
TextEditingController pass = TextEditingController();
|
||||
|
||||
Settings settings = Settings();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("OpenSim - Login"),
|
||||
backgroundColor: Constants.TITLEBAR_COLOR,
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text("First Name"),
|
||||
subtitle: TextField(
|
||||
controller: first,
|
||||
decoration: InputDecoration(hintText: "Jane"),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Last Name"),
|
||||
subtitle: TextField(
|
||||
controller: last,
|
||||
decoration: InputDecoration(hintText: "Smith"),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Password"),
|
||||
subtitle: TextField(
|
||||
controller: pass,
|
||||
obscureText: true,
|
||||
obscuringCharacter: "*",
|
||||
decoration: InputDecoration(hintText: "*******"),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
C2SLoginPacket packet = C2SLoginPacket(
|
||||
first: first.text,
|
||||
last: last.text,
|
||||
password: pass.text);
|
||||
|
||||
var response = await settings.sendPacketToEndpoint(
|
||||
APIEndpoint.Login, packet) as S2CLoginResponsePacket;
|
||||
print("RESPONSE : ${response.encode()}");
|
||||
if (response.loggedIn) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Login success")));
|
||||
|
||||
settings.loggedIn = true;
|
||||
settings.currentUser = response.user;
|
||||
}
|
||||
},
|
||||
child: Text("Login"))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:footer/footer.dart';
|
||||
import 'package:footer/footer_view.dart';
|
||||
import 'package:zontreck/Constants.dart';
|
||||
import 'package:zontreck/pages/LoginAccount.dart';
|
||||
import 'package:zontreck/pages/OpenSim.dart';
|
||||
import 'package:zontreck/pages/Portfolio.dart';
|
||||
import 'package:zontreck/pages/RegisterAccount.dart';
|
||||
|
@ -16,6 +17,7 @@ class MainPage extends StatelessWidget {
|
|||
"/": (context) => const HomePage(),
|
||||
"/opensim": (context) => const OpenSimPage(),
|
||||
"/opensim/register": (context) => RegisterAccountPage(),
|
||||
"/opensim/login": (context) => LoginAccountPage(),
|
||||
"/portfolio": (context) => PortfolioPage(),
|
||||
"/portfolio/coun": (context) => CardsOfUtterNonsense()
|
||||
},
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:footer/footer.dart';
|
||||
import 'package:footer/footer_view.dart';
|
||||
|
@ -24,14 +22,12 @@ class User {
|
|||
required this.userTitle,
|
||||
required this.active});
|
||||
|
||||
static User parseJson(String params) {
|
||||
var map = json.decode(params);
|
||||
|
||||
static User parseJson(Map<String, dynamic> map) {
|
||||
return User(
|
||||
ID: UUID.parse(map['id'] as String),
|
||||
FirstName: map['first'] as String,
|
||||
LastName: map['last'] as String,
|
||||
createdAt: map['rezzed'] as int,
|
||||
createdAt: map['rez'] as int,
|
||||
userTitle: map['title'] as String,
|
||||
active: map['active'] as bool);
|
||||
}
|
||||
|
@ -114,7 +110,11 @@ class OpenSimPageState extends State<OpenSimPage> {
|
|||
child: Row(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {}, child: Text("Login")),
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
context, "/opensim/login");
|
||||
},
|
||||
child: Text("Login")),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(
|
||||
|
|
|
@ -14,6 +14,15 @@ $password = $js["password"];
|
|||
// Compare against hash in database + : md5(salt)
|
||||
$DB = get_DB();
|
||||
|
||||
$id = NULLKEY;
|
||||
$first = "";
|
||||
$last = "";
|
||||
$rezday = 0;
|
||||
$title = "";
|
||||
$login = false;
|
||||
$reason = "Invalid password";
|
||||
$active = false;
|
||||
|
||||
$clientKey = $js['clientKey'];
|
||||
if($clientKey == CLIENTPSK) {
|
||||
// PSK Matches, authorized application
|
||||
|
@ -32,14 +41,6 @@ if($clientKey == CLIENTPSK) {
|
|||
reason: map['reason'] as String,
|
||||
user: User.parseJson(json.encode(map['user'])));
|
||||
*/
|
||||
$id = NULLKEY;
|
||||
$first = "";
|
||||
$last = "";
|
||||
$rezday = 0;
|
||||
$title = "";
|
||||
$login = false;
|
||||
$reason = "Invalid password";
|
||||
$active = false;
|
||||
|
||||
if($res->num_rows > 0) {
|
||||
$row = $res->fetch_assoc();
|
||||
|
@ -64,27 +65,21 @@ if($clientKey == CLIENTPSK) {
|
|||
$reason = "No such user";
|
||||
}
|
||||
|
||||
die(json_encode(
|
||||
array(
|
||||
"login" => $login,
|
||||
"reason" => $reason,
|
||||
"type" => "S2CLoginResponse",
|
||||
"user" => array(
|
||||
"id" => $id,
|
||||
"first" => $first,
|
||||
"last" => $last,
|
||||
"title" => $title,
|
||||
"rez" => $rezday,
|
||||
"active" => $active
|
||||
)
|
||||
)
|
||||
));
|
||||
} else {
|
||||
die(json_encode(array(
|
||||
"login" => false,
|
||||
"reason" => "Unauthorized",
|
||||
"type" => "S2CLoginResponse"
|
||||
)));
|
||||
}
|
||||
|
||||
die(json_encode(
|
||||
array(
|
||||
"login" => $login,
|
||||
"reason" => $reason,
|
||||
"type" => "S2CLoginResponse",
|
||||
"user" => array(
|
||||
"id" => $id,
|
||||
"first" => $first,
|
||||
"last" => $last,
|
||||
"title" => $title,
|
||||
"rez" => $rezday,
|
||||
"active" => $active
|
||||
)
|
||||
)
|
||||
));
|
||||
?>
|
Loading…
Reference in a new issue