import 'package:aitrainer_app/model/cache.dart'; import 'package:aitrainer_app/model/user.dart'; import 'package:aitrainer_app/service/customer_service.dart'; import 'package:aitrainer_app/service/firebase_api.dart'; class UserRepository { User user; UserRepository() { this.createNewUser(); } setEmail(String email) { this.user.email = email; } setPassword(String password) { this.user.password = password; } createNewUser() { this.user = User(); } Future addUser() async { final User modelUser = this.user; try { String rc = await FirebaseApi().registerEmail(modelUser.email, modelUser.password); if (rc == FirebaseApi.SIGN_IN_OK) { modelUser.firebaseUid = Cache().firebaseUid; await CustomerApi().addUser(modelUser); } } catch (e) { print(e.toString()); throw new Exception(e); } } Future getUser() async { final User modelUser = this.user; String rc = await FirebaseApi().signInEmail(modelUser.email, modelUser.password); if (rc == FirebaseApi.SIGN_IN_OK) { await CustomerApi().getUserByEmail(modelUser.email); Cache().afterFirebaseLogin(); } else { print("Exception: user not found or password is wrong"); throw Exception("Customer does not exist or the password is wrong"); } } Future resetPassword() async { final User modelUser = this.user; await FirebaseApi().resetPassword(modelUser.email); } }