private async Task <bool> TryLoginAsync() { await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Storage); await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location); string username = Settings.Email; string password = Settings.Password; var loader = await MaterialDialog.Instance.LoadingDialogAsync("Signing In"); AuthServices auth = new AuthServices(); var result = await auth.Login(username, password); if (result.Success) { Constants.UserProfile = result; FirebaseTokenService firebaseToken = new FirebaseTokenService(); var tokenResult = await firebaseToken.InsertFirebaseToken(result.LabID, result.Role, Settings.FirebaseToken, App.IsAndroid, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff")); if (tokenResult.Success) { return(true); } else { await MaterialDialog.Instance.AlertAsync(tokenResult.Message); } } else { await MaterialDialog.Instance.AlertAsync(result.Message); } await loader.DismissAsync(); return(false); }
private async void LoginCommandAsync(object obj) { await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Storage); await PermissionUtils.CheckPermissions(Plugin.Permissions.Abstractions.Permission.Location); var loader = await MaterialDialog.Instance.LoadingDialogAsync("Signing In"); Models.UserProfileModel result = new Models.UserProfileModel(); if (Settings.IsRemember && Settings.Email != string.Empty && Settings.Password != string.Empty) { //result = await AuthServices.Login(Settings.Email, Settings.Password); result = new Models.UserProfileModel { Email = Settings.Email, LabID = Settings.LabId, UserID = Settings.UserID, UserPass = Settings.Password, Role = Settings.Role, Name = Settings.Name, Phone = Settings.Phone }; Constants.UserProfile = result; App.Current.MainPage = new NavigationPage(new HomeView()); } else { if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password)) { await MaterialDialog.Instance.AlertAsync("Please fill both the fields to continue"); return; } result = await AuthServices.Login(Username, Password); } if (result.Success) { Constants.UserProfile = result; if (RememberChecked) { Settings.Email = !String.IsNullOrEmpty(Constants.UserProfile.Email) ? Constants.UserProfile.Email : Constants.UserProfile.UserID; Settings.Password = Constants.UserProfile.UserPass; Settings.Role = result.Role; Settings.LabId = result.LabID; Settings.Name = result.Name; Settings.Phone = result.Phone; Settings.UserID = result.UserID; Settings.IsRemember = true; } var tokenResult = await FirebaseTokenService.InsertFirebaseToken(result.LabID, result.Role, Settings.FirebaseToken, App.IsAndroid, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fff")); if (tokenResult.Success) { if (String.IsNullOrEmpty(Constants.UserProfile.Email)) { //await PushAsync(new SignUpPage()); await this.Navigation.PushAsync(new SignUpPage(), false); //App.Current.MainPage = new NavigationPage(new SignUpPage()); } else { App.Current.MainPage = new NavigationPage(new HomeView()); } } else { await UserDialogs.Instance.AlertAsync(tokenResult.Message); } } else { await MaterialDialog.Instance.AlertAsync(result.Message); } await loader.DismissAsync(); }