Signup screen and functionality
This commit is contained in:
1 parent
08f0668997
commit
c3e55e89f2
6 files changed
+155
-11
No files matched your search
@@ -1,7 +1,8 @@
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:html';
|
||||
import 'dart:convert';
|
||||
import 'dart:async'; // Import for handling Completers
|
||||
import 'dart:async';
|
||||
|
||||
class ChatInfo {
|
||||
int id;
|
||||
@@ -31,6 +32,23 @@ class Backend {
|
||||
connect();
|
||||
}
|
||||
|
||||
static Future<void> signup(String username, String email, String password) async {
|
||||
final response = await http.post(Uri.parse("$_url/user/signup"),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: jsonEncode({
|
||||
'username': username,
|
||||
'email': email,
|
||||
'password': password,
|
||||
})
|
||||
);
|
||||
|
||||
if (response.statusCode < 200 || response.statusCode >= 300) {
|
||||
throw Exception("Signup Status Code ${response.statusCode}");
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> auth(String username, String password) {
|
||||
_socket!.send(json.encode({'username': username, 'password': password}));
|
||||
_credentials = (username: username, password: password);
|
||||
@@ -43,7 +61,7 @@ class Backend {
|
||||
}
|
||||
|
||||
static void connect() {
|
||||
_socket = WebSocket(_url!);
|
||||
_socket = WebSocket(_url! + "/ws");
|
||||
_socket!.onOpen.listen((event) {
|
||||
print('Connected to the WebSocket server');
|
||||
Backend.invalidateCache(chat: true);
|
||||
|
||||
Reference in new issue
Block a user