Browse Source

files of David. I changed only AuthService file

iwa-42 3 năm trước cách đây
mục cha
commit
644d88207d

+ 57 - 0
app/lib/Services/AuthServiec.dart

@@ -0,0 +1,57 @@
+import 'package:cloud_firestore/cloud_firestore.dart';
+import 'package:firebase_auth/firebase_auth.dart';
+import 'package:physigo/Services/DatabaseManager.dart';
+
+class AuthenticationServices {
+  final FirebaseAuth _auth = FirebaseAuth.instance;
+  late User user;
+
+  //Register a user
+  Future createNewUser(String address, bool anonymous, String birth,
+      String name, String email, String password, String phone, String sharedID,
+      String surname) async {
+    try {
+      UserCredential result = await _auth.createUserWithEmailAndPassword(
+          email: email, password: password);
+      User? user = result.user;
+      await DatabaseManager("total_points").createUserData(
+          address, anonymous, birth, DateTime.now(), DateTime.now(), email,
+          name, phone, sharedID, surname, 0, DateTime.now(), 'null', user!.uid);
+
+      return user;
+    } catch (e) {
+      print(e.toString());
+    }
+  }
+
+  //LogIn with user
+  Future loginUser(String email, String password) async {
+    try {
+      UserCredential result = await _auth.signInWithEmailAndPassword(
+          email: email, password: password);
+      return result.user;
+    } catch(e) {
+      print(e.toString());
+    }
+  }
+
+
+  Future <dynamic> getCurrentUser() async{
+    User? user = _auth.currentUser;
+    var querySnapshot = await FirebaseFirestore.instance.collection('profileInfo')
+        .where('mail', isEqualTo: user?.email)
+        .get();
+    return querySnapshot;
+  }
+
+
+  Stream<int> getPlace(dynamic user) async*{
+    var users = await FirebaseFirestore.instance.collection('Users').
+    where("total_points", isGreaterThan: user["total_points"])
+        .get();
+    yield users.docs.length + 1;
+  }
+
+
+
+}

+ 5 - 8
app/lib/Services/DatabaseManager.dart

@@ -1,10 +1,14 @@
 //import 'package:cloud_firestore/cloud_firestore.dart';
 import 'package:cloud_firestore/cloud_firestore.dart';
-import 'package:flutter/cupertino.dart';
 
 class DatabaseManager {
+  late final String points;
   final CollectionReference profileList =
   FirebaseFirestore.instance.collection('profileInfo');
+  CollectionReference usersList =
+  FirebaseFirestore.instance.collection("Users");
+
+  DatabaseManager(this.points);
 
   Future<void> createUserData(String address,
       bool anonymous,
@@ -37,11 +41,4 @@ class DatabaseManager {
       'weekly_place': weeklyplace,
     });
   }
-
-  Future getusersList(String id) async {
-  }
 }
-//  FirebaseFirestore.instance.collection('profileInfo').doc(arguments['id'])
-//         .get().then((DocumentSnapshot) =>
-//         print('____'+DocumentSnapshot.data().toString())
-//     );

+ 0 - 1
app/lib/SignupPage.dart

@@ -1,7 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:physigo/Services/AuthService.dart';
 
-import 'Services/DatabaseManager.dart';
 
 //Fields..
 TextEditingController _name = TextEditingController();