示例#1
0
        private async void LoginClicked(System.Object sender, System.EventArgs e)
        {
            if (UserEntry.Text == null || UserEntry.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Non hai inserito l'username", Color.Red);
                return;
            }
            else if (PassEntry.Text == null || PassEntry.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Non hai inserito la password", Color.Red);
                return;
            }

            UserModel userFound = await App.apiHelper.tryLogin(UserEntry.Text, PassEntry.Text);

            if (userFound != null)
            {
                Application.Current.Properties["id"]       = userFound.id;
                Application.Current.Properties["username"] = userFound.username;
                Application.Current.Properties["password"] = PassEntry.Text;
                Application.Current.Properties["walletid"] = userFound.walletid;
                LoggedIn();
            }
            else
            {
                PassEntry.Text = "";
                notificationSystem.AddNewNotification("Errore", "Username o password errati", Color.Red);
                return;
            }
        }
示例#2
0
        private async void LoadNotifications()
        {
            if (!Application.Current.Properties.ContainsKey("id"))
            {
                return;
            }
            List <NotificationModel> notes = await App.apiHelper.getNotificationsOfUser(Application.Current.Properties["id"].ToString());

            foreach (var nota in notes)
            {
                if (!nota.seen)
                {
                    notificationSystem.AddNewNotification(nota.title, nota.message, Xamarin.Forms.Color.White);
                    App.apiHelper.updateNotificationById(nota.id);
                }
            }
        }
示例#3
0
        async void StartTransiction(System.Object sender, System.EventArgs e)
        {
            //Effettua pagamento
            if (EntryImporto.Text == null || EntryImporto.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Inserisci l'importo da inviare", Color.Red);
                return;
            }
            else if (EntryWallet.Text == null || EntryWallet.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Inserisci il Wallet ID a cui vuoi inviare il denaro", Color.Red);
                return;
            }
            else if (double.Parse(EntryImporto.Text) - Math.Truncate(double.Parse(EntryImporto.Text)) != 0 && double.Parse(EntryImporto.Text) - Math.Truncate(double.Parse(EntryImporto.Text)) < 0.000001)
            {
                notificationSystem.AddNewNotification("Errore", "Il valore decimale dell'importo è troppo grande (massimo 6 cifre)", Color.Red);
                return;
            }
            else if (double.Parse(EntryImporto.Text) < 0)
            {
                notificationSystem.AddNewNotification("Errore", "Inserisci un numero positivo", Color.Red);
                return;
            }
            else if (EntryWallet.Text == Application.Current.Properties["walletid"].ToString())
            {
                notificationSystem.AddNewNotification("Errore", "Non puoi inviarti soldi da solo! Bruh", Color.Red);
                return;
            }

            //Controlla se il walletId inserito esiste
            string idUtenteDaPagare = (await App.apiHelper.getUserByWalletId(EntryWallet.Text))?.id;

            if (idUtenteDaPagare == null)
            {
                notificationSystem.AddNewNotification("Errore", "Wallet ID non esistente", Color.Red);
                return;
            }

            App.apiHelper.paySomeone(double.Parse(EntryImporto.Text), App.Current.Properties["walletid"].ToString(), EntryWallet.Text);

            await Navigation.PopAsync();
        }
示例#4
0
        private async void CercaPersone(object obj)
        {
            ListaAmici.Children.Clear();
            //Metti la logica della ricerca qua
            List <UserModel> usersFound = await App.apiHelper.searchUsersByUsername(EntrySearch.Text);

            foreach (UserModel user in usersFound)
            {
                if (user.id != Application.Current.Properties["id"].ToString())
                {
                    StackLayout stackUser = new StackLayout {
                        Margin        = new Thickness(10, 0, 10, 0),
                        Orientation   = StackOrientation.Horizontal,
                        Padding       = 0,
                        HeightRequest = 50
                    };
                    ListaAmici.Children.Add(stackUser);
                    stackUser.Children.Add(new Image
                    {
                        Source            = ImageSource.FromStream(() => Identicon.FromValue(user.username, 150).SaveAsPng()),
                        VerticalOptions   = LayoutOptions.CenterAndExpand,
                        HorizontalOptions = LayoutOptions.Start,
                        HeightRequest     = 50,
                        WidthRequest      = 50,
                        Clip = new EllipseGeometry(new Point(25, 25), 25, 25)
                    });
                    stackUser.Children.Add(new Label {
                        Text                  = user.username,
                        TextColor             = Color.Black,
                        FontAttributes        = FontAttributes.Bold,
                        FontSize              = 16,
                        HorizontalOptions     = LayoutOptions.Start,
                        VerticalOptions       = LayoutOptions.CenterAndExpand,
                        VerticalTextAlignment = TextAlignment.Center
                    });
                    if (friendList.Where(o => o.id == user.id).ToList().Count > 0)
                    {
                        stackUser.Children.Add(new Button
                        {
                            Text              = FontLoader.FriendIcon,
                            FontFamily        = "icon_font",
                            Padding           = 0,
                            FontSize          = 25,
                            TextColor         = Color.Black,
                            BackgroundColor   = Color.Transparent,
                            VerticalOptions   = LayoutOptions.CenterAndExpand,
                            HorizontalOptions = LayoutOptions.EndAndExpand
                        });
                    }
                    else
                    {
                        Button addFriendBtn = new Button
                        {
                            Text              = FontLoader.PlusIcon,
                            FontFamily        = "icon_font",
                            Padding           = 0,
                            FontSize          = 25,
                            TextColor         = Color.Green,
                            BackgroundColor   = Color.Transparent,
                            VerticalOptions   = LayoutOptions.CenterAndExpand,
                            HorizontalOptions = LayoutOptions.EndAndExpand,
                        };
                        addFriendBtn.Clicked += async(sender, e) => {
                            await App.apiHelper.createNewFriendship(user.id);

                            App.apiHelper.sendNotification(user.id, "Nuova richiesta", App.Current.Properties["username"] + " ti ha inviato una richiesta di amicizia");
                            notificationSystem.AddNewNotification("Aggiunto!", "Hai mandato una richiesta di amicizia a " + user.username, Color.Green);
                        };
                        stackUser.Children.Add(addFriendBtn);
                    }
                }
            }
        }
        private async void RegisterClicked(object sender, EventArgs e)
        {
            if (UserEntry.Text == null || UserEntry.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Non hai inserito un username", Color.Red);
                return;
            }
            else if (UserEntry.Text.Length > 16)
            {
                notificationSystem.AddNewNotification("Errore", "L'username è troppo lungo", Color.Red);
                return;
            }
            else if (UserEntry.Text.Length < 4)
            {
                notificationSystem.AddNewNotification("Errore", "L'username è troppo corto", Color.Red);
                return;
            }
            else if (PassEntry.Text == null || PassEntry.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Non hai inserito una password", Color.Red);
                return;
            }
            else if (PassEntry2.Text == null || PassEntry2.Text.Trim() == "")
            {
                notificationSystem.AddNewNotification("Errore", "Non hai confermato la password", Color.Red);
                return;
            }
            else if (PassEntry.Text != PassEntry2.Text)
            {
                notificationSystem.AddNewNotification("Errore", "Le due password non corrispondono", Color.Red);
                return;
            }

            //Tutto in regola
            notificationSystem.AddNewNotification("Invio", "Attendi un attimo...", Color.Orange);

            //Controlla che l'username non esista già
            List <UserModel> listSameUser = await App.apiHelper.searchUsersByUsername(UserEntry.Text);

            if (listSameUser != null)
            {
                foreach (var possibleUser in listSameUser)
                {
                    if (possibleUser.username == UserEntry.Text)
                    {
                        notificationSystem.AddNewNotification("Errore", "L'username è già in uso, scegline un altro", Color.Red);
                        return;
                    }
                }
            }

            bool successfulRegistration = await App.apiHelper.tryRegister(UserEntry.Text, PassEntry.Text);

            if (successfulRegistration)
            {
                notificationSystem.AddNewNotification("Conferma", "Account creato con successo, torna al login", Color.LightGreen);
            }
            else
            {
                notificationSystem.AddNewNotification("Registrazione fallita", "Account non creato, riprova più tardi", Color.Red);
            }
        }