protected override async void OnStart()
        {
            #region Update user to refresh auth token
            // Check if user is connected to internet, if not, skip this
            if (CheckNetwork.IsInternet())
            {
                UserDatabase uDB         = new UserDatabase();
                var          AppUserData = uDB.GetAllUsers();

                // Check if a user already exists:
                if (AppUserData.Count != 0)
                {
                    User AppUser = new User()
                    {
                        Username = AppUserData[0].Username,
                        Password = AppUserData[0].Password,
                    };

                    var result = await RestService.Login(AppUser);

                    uDB.UpdateUser(result);
                }
            }
            #endregion

            #region AppCenter init
            //AppCenter.Start(
            //    "ios=cadde90a-e7d4-4488-b4df-4ee5f3fbc174;" +
            //    "android=83ece3d7-61ae-4edb-8279-6d8ce9536966",
            //    typeof(Analytics), typeof(Crashes), typeof(Push)
            //);
            #endregion
        }
 public ProductPage()
 {
     InitializeComponent();
     if (CheckNetwork.IsInternet())
     {
         getProducts.LoadAllProducts(ListView, LoadingProducts, loadingProductsLbl);
     }
     else
     {
         ErrMessage.IsVisible = true;
         ErrMessage.TextColor = Color.Red;
         ErrMessage.Text      = "You're not connected to the internet. Please make sure you are connected to use the app.";
     }
 }
Beispiel #3
0
 public ProductDetail(object e)
 {// Check if user is connected to internet, if not, skip this
     if (CheckNetwork.IsInternet())
     {
         BindingContext = e;
     }
     else
     {
         ErrMessage.IsVisible = true;
         ErrMessage.TextColor = Color.Red;
         ErrMessage.Text      = "You're not connected to the internet. Please make sure you are connected to use the app.";
     }
     InitializeComponent();
 }
Beispiel #4
0
 public ContactPage()
 {
     InitializeComponent();
     if (CheckNetwork.IsInternet())
     {
         // Code
     }
     else
     {
         ErrMessage.IsVisible = true;
         ErrMessage.TextColor = Color.Red;
         ErrMessage.Text      = "You're not connected to the internet. Please make sure you are connected to use the app.";
     }
 }
Beispiel #5
0
 public AccountPage()
 {
     InitializeComponent();
     // Check if user is connected to internet, if not, skip this
     if (CheckNetwork.IsInternet())
     {
         var userDatabase = new UserDatabase();
         var userdata     = userDatabase.GetAllUsers();
         if (userdata.Count < 1)
         {
             BtnLoginProcess.IsVisible    = true;
             LblAccountText.IsVisible     = true;
             LblUserName.IsVisible        = false;
             BtnLogoutProcess.IsVisible   = false;
             BtnRegisterProcess.IsVisible = true;
         }
         else
         {
             var Displayname = userdata.First().Displayname;
             BtnLoginProcess.IsVisible    = false;
             LblUserName.Text             = "Welcome " + Displayname;
             LblUserName.TextColor        = Color.White;
             LblUserName.IsVisible        = true;
             LblAccountText.IsVisible     = false;
             BtnLogoutProcess.IsVisible   = true;
             BtnRegisterProcess.IsVisible = false;
         }
     }
     else
     {
         BtnLoginProcess.IsVisible    = false;
         LblAccountText.IsVisible     = false;
         BtnLogoutProcess.IsVisible   = false;
         BtnRegisterProcess.IsVisible = false;
         LblUserName.IsVisible        = false;
         LblAccountText.IsVisible     = false;
         ErrMessage.IsVisible         = true;
         ErrMessage.TextColor         = Color.Red;
         ErrMessage.Text = "You're not connected to the internet. Please make sure you are connected to use the app.";
     }
 }
        private async void ToCreateProduct(object sender, EventArgs e)
        {
            if (CheckNetwork.IsInternet())
            {
                var userDatabase = new UserDatabase();
                var userdata     = userDatabase.GetAllUsers();
                if (userdata.Count == 1)
                {
                    await Navigation.PushAsync(new CreateProduct());
                }
                else
                {
                    await DisplayAlert("Error", "You must be logged in to create an ad.", "Ok");

                    await Navigation.PushAsync(new LoginPage());
                }
            }
            else
            {
                ErrMessage.IsVisible = true;
                ErrMessage.TextColor = Color.Red;
                ErrMessage.Text      = "You're not connected to the internet. Please make sure you are connected to use the app.";
            }
        }
Beispiel #7
0
        async void LoginRequest(object sender, EventArgs e)
        {
            if (CheckNetwork.IsInternet())
            {
                var user = new User
                {
                    Username = EntryUsername.Text,
                    Password = EntryPassword.Text
                };

                if (user.Username == "" || user.Password == "")
                {
                    LblLogingin.TextColor = Color.Red;
                    LblLogingin.Text      = "Please fill in the fields before logging in!";
                }
                else
                {
                    LblLogingin.TextColor = Color.GreenYellow;
                    LblLogingin.Text      = "Logging in! please wait.....";
                    var result = await App.RestserviceLogin.Login(user);

                    Console.WriteLine("Add result");
                    var dbclear = new UserDatabaseController();
                    dbclear.UserDatabase();
                    Console.WriteLine("DbCLEAR AREA");
                    dbclear.Droptable();
                    Console.WriteLine("Passed Droptable");
                    if (result.remember_token != null)
                    {
                        Console.WriteLine("Token is not null");
                        if (result.IsFrozen == 0)
                        {
                            Console.WriteLine("Not Frozen");
                            var userDatabase = new UserDatabaseController();
                            userDatabase.AddUser(result);
                            var DashBoard = new NavigationPage(new Dashboard());
                            NavigationPage.SetHasNavigationBar(DashBoard, false);
                            await Navigation.PushAsync(DashBoard);

                            LblLogingin.Text   = "";
                            EntryPassword.Text = "";
                        }
                        else
                        {
                            LblLogingin.TextColor = Color.Red;

                            LblLogingin.Text = "Your account has been deactivated. Please contact a administrator";
                        }
                    }
                    else
                    {
                        LblLogingin.TextColor = Color.Red;

                        LblLogingin.Text = "Invalid login information... please try again!";
                    }
                }
            }
            else
            {
                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                LblLogingin.HorizontalTextAlignment = TextAlignment.Center;
                LblLogingin.Text =
                    "OOPS! Please connect to a network first.";
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(170, 0, 0);
                await Task.Delay(250);

                LblLogingin.TextColor = Color.FromRgb(255, 0, 0);
                LblLogingin.Text      = "";
            }
        }
Beispiel #8
0
        //public ActivityIndicator Submitting_Indicator { get { return submittin; } }

        public CreateProduct()
        {
            InitializeComponent();
            MainImage.IsVisible = false;
            //createProductProcess.IsEnabled = false;

            #region Taking a photo
            takePhoto.Clicked += async(sender, args) =>
            {
                Loading_Indicator.IsVisible = true;
                await CrossMedia.Current.Initialize();

                await CreateProductProgress.ProgressTo(0.3, 200, Easing.Linear);

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", "No Camera Available.", "OK");

                    return;
                }
                file = await CrossMedia.Current.TakePhotoAsync(
                    new StoreCameraMediaOptions
                {
                    SaveToAlbum   = true,
                    AllowCropping = true,
                });

                await CreateProductProgress.ProgressTo(0.3, 600, Easing.Linear);

                MainImage.IsVisible         = true;
                Loading_Indicator.IsVisible = false;
                if (file == null)
                {
                    return;
                }


                MainImage.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return(stream);
                });
                createProductProcess.IsEnabled = true;
            };
            #endregion

            #region Picking a photo
            pickPhoto.Clicked += async(sender, args) =>
            {
                //CreateProductProgress.ProgressTo(1,200, Easing.Linear);
                Loading_Indicator.IsVisible    = true;
                createProductProcess.IsEnabled = false;
                await CrossMedia.Current.Initialize();

                await CreateProductProgress.ProgressTo(0.3, 200, Easing.Linear);

                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("Photos Not Supported", "Permission not granted to photos.", "OK");

                    return;
                }
                await CreateProductProgress.ProgressTo(0.3, 600, Easing.Linear);

                file = await CrossMedia.Current.PickPhotoAsync();

                MainImage.IsVisible         = true;
                Loading_Indicator.IsVisible = false;

                if (file == null)
                {
                    return;
                }

                MainImage.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    return(stream);
                });
                createProductProcess.IsEnabled = true;
            };
            #endregion

            #region clicking button to post item
            createProductProcess.Clicked += async(sender, args) =>
            { // Check if user is connected to internet, if not, skip this
                if (CheckNetwork.IsInternet())
                {
                    createProductProcess.Text      = "Submitting";
                    createProductProcess.IsEnabled = false;

                    // Check if all fields are filled
                    if (Product_Title.Text != "" &&
                        Product_City.Text != "" &&
                        Product_State.Text != "" &&
                        Product_Model.Text != "" &&
                        Product_Make.Text != "" &&
                        Product_Year.Text != "" &&
                        Product_Price.Text != "" &&
                        MainImage.Source != null &&
                        Product_Description.Text != "")
                    {
                        CreateProductProgress.IsVisible = true;
                        await CreateProductProgress.ProgressTo(0.3, 700, Easing.Linear);

                        string priceDouble = string.Format("{0:C}", Product_Price.Text);

                        List <Category> Categories = new List <Category>();

                        Product product = new Product(
                            Product_Title.Text,
                            Product_Price.Text,
                            //priceDouble,
                            Product_Description.Text,
                            $"{Product_City.Text}, {Product_State.Text}, {Product_Model.Text}, {Product_Make.Text}, {Product_Year.Text}",
                            Categories
                            );

                        //UploadProduct(product, file);

                        await CreateProductProgress.ProgressTo(1, 600, Easing.Linear);
                    }
                    else
                    {
                        createProductProcess.Text = "Submit";
                        Message.TextColor         = Color.Red;
                        Message.Text = "Not all fields were filled. Please revise and try again.";
                        createProductProcess.IsEnabled = true;
                    }
                    Navigation.InsertPageBefore(new Index(), this);
                    await Navigation.PopAsync();
                }
                else
                {
                    ErrMessage.IsVisible = true;
                    ErrMessage.TextColor = Color.Red;
                    ErrMessage.Text      = "You're not connected to the internet. Please make sure you are connected to use the app.";
                }
            };
        }
        private async void RegisterProcess_Clicked(object sender, EventArgs e)
        {
            RegisterMessage.TextColor = Color.LightGreen;
            RegisterMessage.Text      = "Registration in progress...";
            // Check if user has an internet connection. If there IS a connection, continue with the login process
            if (CheckNetwork.IsInternet())
            {
                // Creating new user and setting Username and Password to the input from the login page
                var user = new User
                {
                    Username = Entry_Username.Text,
                    Password = Entry_Pass.Text,
                    Nicename = Entry_Nicename.Text,
                    Email    = Entry_Email.Text,
                };

                if (Entry_Username.Text != null && Entry_Pass.Text != null && Entry_ConfirmPass.Text != null && Entry_Email.Text != null && Entry_Nicename.Text != null)
                {
                    indicator.IsVisible = true;
                    if (Entry_Pass.Text == Entry_ConfirmPass.Text)
                    {
                        // Using hard coded admin to use it's bearer so we can register a user as this requires administrator access
                        var userAuth = new User
                        {
                            Username = "******",
                            Password = "******"
                        };

                        // Login the administrator
                        var authUser = await App.RestService.Login(userAuth);

                        // Setting bearer to the accesstoken we received from the admin (Can't hardcode the token as it refreshes every so often)
                        var bearer = authUser.AccessToken;
                        Constants.CreateUserToken = bearer;

                        if (user.Username.Length > 5)
                        {
                            if (Regex.Match(user.Username, @"^[a-zA-Z ]+$").Success)
                            {
                                if (user.Nicename.Length > 5)
                                {
                                    if (Regex.Match(user.Nicename, @"^[a-zA-Z ]+$").Success)
                                    {
                                        // Check if user already exist by searing for it's username
                                        var doesUserExist = await App.RestService.DoesUserExist(user);

                                        if (doesUserExist)
                                        {
                                            RegisterMessage.TextColor = Color.Red;
                                            RegisterMessage.Text      = "This username already exists. Please revise and try again.";
                                        }
                                        else
                                        {
                                            var userEmail = user.Email;
                                            var email     = userEmail.ToLower();

                                            var emailPattern = "^(?(\")(\".+?(?<!\\\\)\"@)|(([0-9a-z]((\\.(?!\\.))|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[0-9a-z])@))(?(\\[)(\\[(\\d{1,3}\\.){3}\\d{1,3}\\])|(([0-9a-z][-\\w]*[0-9a-z]*\\.)+[a-z0-9][\\-a-z0-9]{0,22}[a-z0-9]))$";
                                            if (Regex.Match(email, emailPattern).Success)
                                            {
                                                // Sending the user's input to the register logic
                                                var registerResult = await App.RestService.Register(user);

                                                if (registerResult.WP_Id != 0)
                                                {
                                                    RegisterMessage.TextColor = Color.LightGreen;
                                                    RegisterMessage.Text      = "Registration successfull. Logging you in.";
                                                    var loginResult = await App.RestService.Login(user);

                                                    UserDatabase uDB = new UserDatabase(); loginResult.Username = user.Username;
                                                    loginResult.Password = user.Password;
                                                    loginResult.Nickname = user.Nicename;
                                                    loginResult.Email    = user.Email;
                                                    uDB.AddUser(loginResult);
                                                    var AppUserData = uDB.GetAllUsers();
                                                    Console.WriteLine(AppUserData);

                                                    await Task.Delay(1000);

                                                    Navigation.InsertPageBefore(new Index(), this);
                                                    await Navigation.PopAsync();
                                                }
                                            }
                                            else
                                            {
                                                RegisterMessage.TextColor = Color.Red;
                                                RegisterMessage.Text      = "Email is not in correct format. Please revise and try agian.";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        RegisterMessage.TextColor = Color.Red;
                                        RegisterMessage.Text      = "Full name must only contain letters. Please revise and try again.";
                                    }
                                }
                                else
                                {
                                    RegisterMessage.TextColor = Color.Red;
                                    RegisterMessage.Text      = "Full name must be at least 6 characters long. Please revise and try again.";
                                }
                            }
                            else
                            {
                                RegisterMessage.TextColor = Color.Red;
                                RegisterMessage.Text      = "Username must only contain letters. Please revise and try again.";
                            }
                        }
                        else
                        {
                            RegisterMessage.TextColor = Color.Red;
                            RegisterMessage.Text      = "Username must be at least 6 characters long. Please revise and try again.";
                        }
                    }
                    else
                    {
                        RegisterMessage.TextColor = Color.Red;
                        RegisterMessage.Text      = "Password and Confirm password do not match. Please revise and try again.";
                    }
                }
                else
                {
                    RegisterMessage.TextColor = Color.Red;
                    RegisterMessage.Text      = "Not all fields were filled. Please revise and try again.";
                }
            }
            // If user does not have an internetconnection, return this error
            else
            {
                RegisterMessage.TextColor = Color.Red;
                RegisterMessage.Text      = "You're not connected to the internet!";
            }
            indicator.IsVisible = false;
        }
Beispiel #10
0
        // LoginProcess, this is being called from the Login button on the login page
        private async void LoginProcess_Clicked(object sender, EventArgs e)
        {
            indicator.IsVisible = true;
            // Check if user has an internet connection. If there IS a connection, continue with the login process
            if (CheckNetwork.IsInternet())
            {
                // Creating new user and setting Username and Password to the input from the login page
                var user = new User
                {
                    Username = Entry_Username.Text,
                    Password = Entry_Pass.Text
                };
                // Check if input fields are empty and display error in LoginMessage label if a field, or both, are empty
                if (user.Username == "" || user.Password == "")
                {
                    LoginMessage.TextColor = Color.Red;
                    LoginMessage.Text      = "Username or password field is empty";
                }
                // If all fields are filled continue and display "Loggin in! Please wait..." in the LoginMessage label on the loginpage
                else
                {
                    LoginMessage.TextColor = Color.SpringGreen;
                    LoginMessage.Text      = "Logging in! Please wait...";

                    var result = await App.RestService.Login(user);

                    var dbclear = new UserDatabase();
                    dbclear.Droptable();
                    // Check if you get an AccessToken from the local database. (One will be stored there with the user if login is successful)
                    // If an accesstoken exists in the local database, continue with the login
                    if (result.AccessToken != null)
                    {
                        // Setting user info to result info from login
                        user.Id         = result.Id;
                        result.Username = user.Username;
                        result.Password = user.Password;
                        user.Nicename   = result.Displayname;
                        user.Email      = result.Email;

                        var userDatabase = new UserDatabase();
                        userDatabase.AddUser(result);

                        //userDatabase.UpdateUser(result);

                        LoginMessage.Text = "";
                        Entry_Pass.Text   = "";
                        LoginMessage.Text = "Logged in!";
                        await Task.Delay(1000);

                        Navigation.InsertPageBefore(new Index(), this);
                        await Navigation.PopAsync();
                    }
                    // If no accesstoken was found, the user wasn't logged in due to invalid login info and an error is returned to the loginpage
                    else
                    {
                        LoginMessage.TextColor = Color.Red;
                        LoginMessage.Text      = "Invalid login information... Please try again!";
                    }
                }
            }
            // If user does not have an internetconnection, return this error
            else
            {
                LoginMessage.TextColor = Color.Red;
                LoginMessage.Text      = "You're not connected to the internet!";
            }
            indicator.IsVisible = false;
        }