/*/ * Log into the Database and check if user is either online or offline, * if offline then use local data from last used account * * PARAM begin: checks whenever the UserModel has only accessed the page once. * RETURNS Nothing */ public async Task LoginCommandDatabase() { IsVisible = true; IsRunning = true; FirebaseUser client = new FirebaseUser(); var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Users";//Get folder path try { switch (await client.Login(_UserModel.Username, _UserModel.Password)) { case 0: await LoadUser(client, documents); break; case 1: await OfflineLogin(documents); break; case 2: throw new Exception("Please input both Username and Password"); case 3: throw new Exception("Incorrect password"); case 4: throw new Exception("Account already in use"); case 5: NoAccount(documents); break; } } catch (Exception es) { if (es != null) { try { await Application.Current.MainPage.DisplayAlert("Error", es.Message, "Close"); }catch { throw new Exception(es.Message); } } } IsVisible = false; IsRunning = false; }
/*/ * Check all files within local folder and see if a login file is still logged in. * If the login file is still logged:true then proceed to bypass login screen and go into * app. * * PARAM begin: checks whenever the UserModel has only accessed the page once. * RETURNS Nothing */ public async Task <bool> OnAppearingAsync(bool begin) { var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);//Get folder path Directory.CreateDirectory(documents + "/Users"); FirebaseUser client = new FirebaseUser(); var files = Directory.GetFiles(documents + "/Users"); var Logged = Path.Combine(documents + "/Users", "Logged.dt"); FadeOut = 0.0; LoggedIsRunning = true; try { foreach (var file in files) { if (Path.GetFileName(file).Contains("Logged")) { switch (await client.Login(UserModel.CheckForstring(file, "Username:"******"Password:"******"Incorrect Password"); case 5: NoAccountLogged(documents, file, Logged); break; } } } } catch (Exception es) { if (es != null) { await Application.Current.MainPage.DisplayAlert("Error", es.Message, "Close"); FadeOut = 100.0; LoggedIsRunning = false; return(false); } } FadeOut = 100.0; LoggedIsRunning = false; if (begin && !CheckAccounts(files)) { var documentz = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Users";//Get folder path File.WriteAllText(Logged, "Username:\nPassword:"******"Welcome", "Welcome to Dungeon Tasker new User", "close"); return(false); } return(false); }