Léo Salé преди 3 години
родител
ревизия
5b6642209f
променени са 3 файла, в които са добавени 24 реда и са изтрити 71 реда
  1. 23 13
      app/lib/Services/AuthService.dart
  2. 0 57
      app/lib/Services/AuthServiec.dart
  3. 1 1
      app/lib/currentUser.dart

+ 23 - 13
app/lib/Services/AuthService.dart

@@ -1,3 +1,4 @@
+import 'package:cloud_firestore/cloud_firestore.dart';
 import 'package:firebase_auth/firebase_auth.dart';
 import 'package:physigo/Services/DatabaseManager.dart';
 
@@ -5,33 +6,42 @@ class AuthenticationServices {
   final FirebaseAuth _auth = FirebaseAuth.instance;
 
   //Register a user
-  Future createNewUser(String address, bool anonymous, String birth,
-      String name, String email, String password, String phone, String sharedID,
-      String surname) async {
+  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);
+      UserCredential result = await _auth.createUserWithEmailAndPassword(email: email, password: password);
       User? user = result.user;
-      await DatabaseManager().createUserData(
-          address, anonymous, birth, DateTime.now(), DateTime.now(), email,
-          name, phone, sharedID, surname, 0, DateTime.now(), 'null', user!.uid);
+      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('catch auto');
       print(e.toString());
-      print('catch auto2');
     }
   }
 
   //LogIn with user
   Future loginUser(String email, String password) async {
     try {
-      UserCredential result = await _auth.signInWithEmailAndPassword(
-          email: email, password: password);
+      UserCredential result = await _auth.signInWithEmailAndPassword(email: email, password: password);
       return result.user;
-    } catch(e) {
+    } 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;
+  }
 }

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

@@ -1,57 +0,0 @@
-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;
-  }
-
-
-
-}

+ 1 - 1
app/lib/currentUser.dart

@@ -1,7 +1,7 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
-import 'Services/AuthServiec.dart';
+import 'Services/AuthService.dart';
 
 class CurrentUser extends StatefulWidget {
   const CurrentUser( {