|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|