Removed Redundant Code
This commit is contained in:
@@ -26,15 +26,9 @@ class MessagingProviders extends ChangeNotifier {
|
||||
// Auth Status
|
||||
AuthStatus? status;
|
||||
|
||||
//User Details
|
||||
models.User? user;
|
||||
models.Session? session;
|
||||
|
||||
// var _email;
|
||||
// var _name;
|
||||
// var _imageURL;
|
||||
// var _timeStamp;
|
||||
|
||||
static MessagingProviders instance = MessagingProviders();
|
||||
|
||||
MessagingProviders() {
|
||||
@@ -62,38 +56,51 @@ class MessagingProviders extends ChangeNotifier {
|
||||
|
||||
void loginWithEmailAndPassword(String _email, String _password) async {
|
||||
//
|
||||
status = AuthStatus.authenticating;
|
||||
notifyListeners();
|
||||
try {
|
||||
session = await account.createEmailPasswordSession(
|
||||
email: _email, password: _password);
|
||||
status != AuthStatus.error;
|
||||
|
||||
// user = await account.get();
|
||||
status = AuthStatus.authenticated;
|
||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${user!.name}");
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
// account.deleteSession(sessionId: 'current');
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
try {
|
||||
status = AuthStatus.authenticating;
|
||||
session = await account.createEmailPasswordSession(
|
||||
email: _email, password: _password);
|
||||
|
||||
status = AuthStatus.authenticated;
|
||||
var value = await database.getDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: session!.userId,
|
||||
);
|
||||
|
||||
SnackBarService.instance
|
||||
.showSnackBarSuccess("Welcome! ${value.data['name']}");
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
account.deleteSession(sessionId: 'current');
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
//
|
||||
}
|
||||
notifyListeners();
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
//
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> createUser(String _email, String _password,
|
||||
Future<void> createUser(String _email, String _password, String _name,
|
||||
Future<void> onSuccess(String _uid)) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
models.User _user = await account.create(
|
||||
userId: ID.unique(), email: _email, password: _password);
|
||||
user = await account.create(
|
||||
userId: ID.unique(), email: _email, password: _password, name: _name);
|
||||
|
||||
status = AuthStatus.authenticated;
|
||||
await onSuccess(_user.$id);
|
||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${_user.email}");
|
||||
await onSuccess(user!.$id);
|
||||
SnackBarService.instance.showSnackBarSuccess("Welcome! ${user!.name}");
|
||||
NavigationService.instance.goBack();
|
||||
NavigationService.instance.navigateToReplacement("home");
|
||||
} on AppwriteException catch (e) {
|
||||
@@ -109,47 +116,60 @@ class MessagingProviders extends ChangeNotifier {
|
||||
|
||||
Future<void> createUserInDB(
|
||||
String _documentId, String _email, String _name, String _imageURL) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
await database.createDocument(
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: _documentId,
|
||||
data: {
|
||||
"name": _name,
|
||||
"email": _email,
|
||||
"timeStamp": DateTime.now().toUtc().toIso8601String(),
|
||||
"image": _imageURL
|
||||
});
|
||||
databaseId: databaseId,
|
||||
collectionId: userCollectionId,
|
||||
documentId: _documentId,
|
||||
data: {
|
||||
"name": _name,
|
||||
"email": _email,
|
||||
"lastSeen": DateTime.now().toUtc().toIso8601String(),
|
||||
"image": _imageURL
|
||||
},
|
||||
permissions: [
|
||||
Permission.read(Role.any()),
|
||||
//Permission.update(Role.user(_documentId)),
|
||||
],
|
||||
);
|
||||
|
||||
status = AuthStatus.authenticated;
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
} on Exception catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
//
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
uploadUserImage(XFile? file, String _uid) async {
|
||||
notifyListeners();
|
||||
try {
|
||||
File _file = File(file!.path);
|
||||
var _test = await storage.createFile(
|
||||
var _message = await storage.createFile(
|
||||
bucketId: imageStorageBucket,
|
||||
fileId: ID.unique(),
|
||||
file: InputFile.fromPath(path: _file.path, filename: file.name),
|
||||
permissions: [
|
||||
Permission.read(Role.any()),
|
||||
// Permission.update(Role.user(_uid))
|
||||
],
|
||||
);
|
||||
|
||||
return "$endPoint/storage/buckets/${_test.bucketId}/files/${_test.$id}/view?project=$projectId";
|
||||
return "$endPoint/storage/buckets/${_message.bucketId}/files/${_message.$id}/view?project=$projectId";
|
||||
} on AppwriteException catch (e) {
|
||||
SnackBarService.instance.showSnackBarError(e.message!);
|
||||
print(e.message);
|
||||
//
|
||||
} on Exception catch (e) {
|
||||
status = AuthStatus.error;
|
||||
user = null;
|
||||
SnackBarService.instance.showSnackBarError(e.toString());
|
||||
//
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user