| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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;
- }
- }
|