aboutsummaryrefslogtreecommitdiff
path: root/lib/models/user.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/user.dart')
-rw-r--r--lib/models/user.dart61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/models/user.dart b/lib/models/user.dart
new file mode 100644
index 0000000..07c2c09
--- /dev/null
+++ b/lib/models/user.dart
@@ -0,0 +1,61 @@
+import 'package:http/http.dart' as http;
+import 'package:flutter_secure_storage/flutter_secure_storage.dart';
+import "dart:convert";
+
+class User {
+ final int id;
+ String? createdAt;
+ String? updatedAt;
+ String? username;
+ String? email;
+ bool? isVerified;
+
+ User({
+ required this.id,
+ this.createdAt,
+ this.updatedAt,
+ this.username,
+ this.email,
+ this.isVerified
+ });
+
+ factory User.fromJson(Map<String, dynamic> json) {
+ return User(
+ id: json["ID"],
+ createdAt: json["CreatedAt"],
+ updatedAt: json["UpdatedAt"],
+ username: json["Username"],
+ email: json["Email"],
+ isVerified: json["IsVerified"]
+ );
+ }
+}
+
+Future<User> userSignUp(User newUser, String password) async {
+ final res = await http.post(
+ Uri.parse("https://openbills.vidhukant.com/api/auth/signup"),
+ headers: <String, String> {
+ "Content-Type": "application/json; charset=UTF-8",
+ },
+ body: jsonEncode(<String, String> {
+ "Username": newUser.username as String,
+ "Password": password,
+ "Email": newUser.email as String,
+ }),
+ );
+
+ final json = jsonDecode(res.body);
+
+ if (res.statusCode != 200) {
+ switch(res.statusCode) {
+ case 404:
+ throw "This user does not exist";
+ case 500:
+ throw "Internal Server Error";
+ default:
+ throw json["error"];
+ }
+ }
+
+ return User.fromJson(json["data"]);
+}