/// <summary> /// It will set the user_Password to null and creates then a new loginData.xml /// </summary> public void Logout() { // It will set true on the Main Page localFileSystem file = new localFileSystem(); CurrentUser = file.GetUser(); CurrentUser.user_Password = null; RememberLogin(CurrentUser); file.DeleteUser(); }
/// <summary> /// Receives the User Login Status /// </summary> protected override void OnStart() { DataAccessHandler.InitDataAccess(DataAccessHandler.InterfaceType.MySqlPhp); localFileSystem file = new localFileSystem(); CurrentUser = file.GetUser(); if (IsLoggedIn) { MainPage = new NavigationPage(new MainMenuPage(CurrentUser)); } else { MainPage = new LoginModalPage(); } // Handle when your app starts }
public async void AddProduct(string productCode) { try { if (!await DataAccessHandler.DataAccess.IsValidKey(productCode)) { await DisplayAlert("Produktcode ungültiger", "Es wurde ein ungültiger Produktcode eingegeben. Bitte anderen code eingeben.", "Neue Eingabe"); return; } localFileSystem file = new localFileSystem(); String userPath = file.AdjustPath(file.GetUser().user_Email); //Gets the Serveradress DataAccessHandler accessHandler = new DataAccessHandler(); string serverAdress = accessHandler.ServerAdress; IFtpClient client = DependencyService.Get<IFtpClient>(); Product product = await DataAccessHandler.DataAccess.GetProductByKey(productCode); List<Product> listUserProducts = await DataAccessHandler.DataAccess.GetUserProducts(file.GetUser()); foreach (var userProducts in listUserProducts) { if (userProducts.product_ID == product.product_ID) { await DisplayAlert("Produkt bereits vorhanden!", "Sie besitzen dieses Produkt bereits", "OK"); return; } } //Loads the List<PContent> of the Product from the server List<PContent> listPContents = await DataAccessHandler.DataAccess.GetPContent(product.product_ID); //Loads the List<PContent> of the Product from the the User-Folder List<PContent> newlistPContents = file.loadContentList(userPath); foreach (PContent pcontent in listPContents) { //stops if the pcontent is empty if (pcontent.content_ID == 0) break; //adds new Pcontent if necessary while (newlistPContents.Count <= pcontent.content_ID) { newlistPContents.Add(null); } //updates PContent newlistPContents[pcontent.content_ID] = pcontent; if (pcontent.content_Kind!=0) { client.DownloadFile(@"Thumbnail/" + pcontent.content_ID + ".png", DependencyService.Get<ISaveAndLoad>().Getpath(file.GetUser().user_Email + @"/Thumbnail/") + pcontent.content_ID + ".png", serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } List<string> contentPath = await DataAccessHandler.DataAccess.GetFileServerPath(pcontent.content_ID); //creates a new p folder for the content_Kind if not exists DependencyService.Get<ISaveAndLoad>().CreateFolder(DependencyService.Get<ISaveAndLoad>().PathCombine( DependencyService.Get<ISaveAndLoad>().Getpath(userPath), "p" + pcontent.content_ID)); foreach (var path in contentPath) { if (pcontent.content_ID == 0) break; //Download for each PContent its Files DependencyService.Get<ISaveAndLoad>().CreateFolder(userPath + @"/p" + pcontent.content_ID); client.DownloadFile(path, DependencyService.Get<ISaveAndLoad>().Getpath(file.GetUser().user_Email) + @"/p" + pcontent.content_ID + @"/" + Path.GetFileName(path), serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } } //Adds the Product to the Product-File from the User List<Product> newUserProducts = file.LoadProductList(); //newUserProducts.Add(product); file.SaveModelsLocal(userPath, newUserProducts, newlistPContents); //Adds the Product to the User in the Database DataAccessHandler.DataAccess.AddProductToUser(product.product_ID, file.GetUser()); DataAccessHandler.DataAccess.SetProductKeyInvalid(productCode); await DisplayAlert("Produkt aktiviert!", "Das Produkt wurde erfolgreiche aktiviert!", "OK"); await Navigation.PushModalAsync(new NavigationPage(new MainMenuPage(file.GetUser()))); } catch (Exception e) { Debug.WriteLine("Fehler beim hinzufügen von Produkt: " + e); await DisplayAlert("Fehler beim Downloaden", "Es gab einen Fehler beim Downloaden, bitte erneut versuchen", "OK"); } }
/// <summary> /// Set current user with user parameter and saves the login in loginData.xml /// </summary> /// <param name="user"></param> public void Login(User user) { localFileSystem file = new localFileSystem(); file.SaveUser(user); RememberLogin(user); }
/// <summary> /// Checks if loginData.xml exists and delete it if so. Definitaly creates a new loginData.xml file /// </summary> /// <param name="user"></param> public async void RememberLogin(User user) { await Task.Run(() => { localFileSystem file = new localFileSystem(); file.SaveUser(user); //string userLoginDataFilePath = UserLoginDataFilePath(); //ISaveAndLoad saveAndLoad = DependencyService.Get<ISaveAndLoad>(); //if(saveAndLoad.fileExist(userLoginDataFilePath)) // saveAndLoad.deleteFile(userLoginDataFilePath); //saveAndLoad.saveUserXml(userLoginDataFilePath, user); }); }
public async Task DownloadInitialContent(User user) { try { localFileSystem files = new localFileSystem(); String userPath = files.AdjustPath(user.user_Email); //A newly created User cant have a folder with the same name in the folder so no check must be implemented files.CreateInitalFolders(userPath); DataAccessHandler accessHandler = new DataAccessHandler(); string serverAdress = accessHandler.ServerAdress; IFtpClient client = DependencyService.Get<IFtpClient>(); //Download all Products from the database List<Product> listAllProducts = await DataAccessHandler.DataAccess.GetAllProducts(); List<PContent> newEmptyContent = new List<PContent>(); foreach (var productAll in listAllProducts) { if (productAll.product_ID == 0) break; //Download Thumbnail in Produkte Folder client.DownloadFile(@"Produkte/" + productAll.product_Thumbnail, DependencyService.Get<ISaveAndLoad>().Getpath(@"Produkte/") + productAll.product_Thumbnail, serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } files.SaveUser(user); files.SaveModelsLocal(userPath, listAllProducts, newEmptyContent); //Hier GetALLProducts ansttt nur user products List<Product> listUserProducts = await DataAccessHandler.DataAccess.GetUserProducts(user); List<PContent> newlistPContents = new List<PContent>(); foreach (var product in listUserProducts) { //loads the PContent from the server List<PContent> listUserPContents = await DataAccessHandler.DataAccess.GetPContent(product.product_ID); if (product.product_ID == 0) break; foreach (var pcontent in listUserPContents) { if (pcontent.content_ID == 0) break; //creates a new p folder if not exists for content_Kind DependencyService.Get<ISaveAndLoad>().CreateFolder(DependencyService.Get<ISaveAndLoad>().PathCombine( DependencyService.Get<ISaveAndLoad>().Getpath(userPath), "p" + pcontent.content_ID)); List<string> contentPath = await DataAccessHandler.DataAccess.GetFileServerPath(pcontent.content_ID); foreach (var path in contentPath) { //loads every content from PContent client.DownloadFile(path, DependencyService.Get<ISaveAndLoad>().Getpath(files.GetUser().user_Email) + @"/p" + pcontent.content_ID + @"/" + Path.GetFileName(path), serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } while (newlistPContents.Count <= pcontent.content_ID) { newlistPContents.Add(null); } //updates Pcontent newlistPContents[pcontent.content_ID] = pcontent; if (pcontent.content_Kind != 0) { client.DownloadFile(@"Thumbnail/" + pcontent.content_ID + ".png", DependencyService.Get<ISaveAndLoad>().Getpath(files.GetUser().user_Email + @"/Thumbnail/") + pcontent.content_ID + ".png", serverAdress, accessHandler.FtpName, accessHandler.FtpPassword); } } } //Saves User, Products and PContent XML files.SaveUser(user); files.SaveModelsLocal(userPath, listAllProducts, newlistPContents); } catch (Exception e) { Debug.WriteLine("catched DL Exception: " + e); await DisplayAlert("Fehler beim Downloaden", "Es gab einen Fehler beim Downloaden, bitte erneut versuchen", "OK"); } }
/// <summary> /// Konstruktor der MainMenuPage, welcher eine Instanz der Seite erstellt. /// </summary> /// <param name="user"></param> public MainMenuPage(User user) { DataAccessHandler accessHandler = new DataAccessHandler(); string serverAdress = accessHandler.ServerAdress; files = new localFileSystem(); String userPath = files.AdjustPath(user.user_Email); files.CreateInitalFolders(userPath); //Toolbar ToolbarItem toolButton = new ToolbarItem { Name = "Hinzufügen", Order = ToolbarItemOrder.Primary, Icon = null, Command = new Command(() => Navigation.PushAsync(new AddProduktPage())) }; this.ToolbarItems.Add(toolButton); //? //InitLogout(); //Ende Toolbar //View ProductCollection = new Collection<Product>(); ProductCollection = files.LoadProductList(); List<PContent> PcontentCollection = files.loadContentList(userPath); ScrollView scrollView = new ScrollView(); StackLayout stackLayout = new StackLayout(); foreach (Product product in ProductCollection) { TapGestureRecognizer gesture = new TapGestureRecognizer(); bool owned = files.HasContent(product, PcontentCollection); Color color = Color.FromHex("E2001A"); DetailPage detailPage = new DetailPage(product, userPath); var test = (DependencyService.Get<ISaveAndLoad>().PathCombine(DependencyService.Get<ISaveAndLoad>().Getpath(localFileSystem.productFolderLocation), product.product_ID + product.product_Thumbnail)); if (owned == true) color = Color.FromHex("006AB3"); Frame frame = new Frame { BackgroundColor = color, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Content = new StackLayout { Orientation = StackOrientation.Horizontal, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.StartAndExpand, Children = { new Image { Source = ImageSource.FromFile(DependencyService.Get<ISaveAndLoad>().PathCombine(DependencyService.Get<ISaveAndLoad>().Getpath(localFileSystem.productFolderLocation), product.product_Thumbnail)), VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, HeightRequest = 110 }, new Label { FormattedText = product.product_Name, TextColor = Color.Black, VerticalOptions = LayoutOptions.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), HorizontalOptions = LayoutOptions.Center }, }//ende stacklayout (innen) }//ende stacklayout };//frame ende stackLayout.Children.Add(frame); gesture.Tapped += async (sender, e) => { await Navigation.PushAsync(detailPage); }; frame.GestureRecognizers.Add(gesture); } scrollView.Content = stackLayout; Content = scrollView; BackgroundColor = Color.White; Padding = new Thickness(5, Device.OnPlatform(0, 15, 0), 5, 5); //View Ende }
/// <summary> /// Checks: if Empty Email or password, if valid Email, if valid Login. Password Entry is set as isPassword and the shown Passworddigits only contains zeros. Password will be stored as SHA512StringHash /// </summary> public LoginPage() { BackgroundColor = new Color(255, 255, 255, 1); var button = new Button { Text = "Login", BackgroundColor = Color.FromHex("006AB3") }; button.Clicked += async (sender, e) => { //Checks if the Entry for username or password is empty if (String.IsNullOrEmpty(username.Text) || String.IsNullOrEmpty(password.Text)) { password.Text = ""; await DisplayAlert("Abfragefehler", "E-Mail und Passwort bitte angeben", "Neue Eingabe"); return; } //Checks if the Email Entry is receiving a valid Email String if (!IsValidEmail(username.Text)) { password.Text = ""; await DisplayAlert("Ungültige E-Mail", "E-Mail ist in einem ungültigen Format angegeben worden", "Neue Eingabe"); return; } // Converts Password in SHA512StringHash string passwordHash = DependencyService.Get<IHash>().Sha512StringHash(password.Text); // Sets the Passworddigits to zero after receiving a letter password.Text = new string('0', password.Text.Length); User validUser = await IsValidLogin(new User(username.Text, passwordHash)); // Checks with null parameter if user is valid if (null == validUser) { password.Text = ""; if (_exception) await DisplayAlert("Verbindungsfehler", "Server ist nicht erreichtbar. Internetzugang aktiv?", "OK"); else await DisplayAlert("Ungültiger Login", "E-Mail oder Passwort falsch angegeben", "Neue Eingabe"); } else { localFileSystem file = new localFileSystem(); App.Current.Login(validUser); if (!DependencyService.Get<ISaveAndLoad>().FileExist(DependencyService.Get<ISaveAndLoad>().PathCombine(file.AdjustPath( validUser.user_Email), "PContent"))) { Debug.WriteLine("getphath2 " + DependencyService.Get<ISaveAndLoad>().Getpath("")); await DisplayAlert("Neue Anmeldung", "Sie haben sich an einem neuen Gerät angemeldet. Daten werden runtergeladen", "OK"); CreateAccountPage cap = new CreateAccountPage(); await cap.DownloadInitialContent(validUser); } await Navigation.PushModalAsync(new NavigationPage(new MainMenuPage(validUser))); } }; var create = new Button { Text = "Account erstellen", BackgroundColor = Color.FromHex("E2001A") }; create.Clicked += (sender, e) => { MessagingCenter.Send<ContentPage>(this, "Erstellen"); }; //Receives the CurrentUser and Set the Entry field as the Email from the last user with a valid Login username = new Entry { Text = App.Current.CurrentUser != null ? App.Current.CurrentUser.user_Email : "", BackgroundColor = Color.FromHex("3f3f3f") }; password = new Entry { Text = "", BackgroundColor = Color.FromHex("3f3f3f"), IsPassword = true }; Content = new StackLayout { Padding = new Thickness(10, 40, 10, 10), //VerticalOptions = LayoutOptions.Center, Children = { new Label { Text = "Login", TextColor = Color.FromHex("006AB3"), FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)) }, new Label { Text = "E-Mail", TextColor = Color.FromHex("000000")}, username, new Label { Text = "Passwort", TextColor = Color.FromHex("000000")}, password, button, create } }; }