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
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        /// <param name="currentUser">All the required information about the current logged in user.</param>
        /// <param name="data">Instance of <see cref="DataComponents"/> that allows access to user database and certificates.</param>
        /// <param name="thisWindow">Window in which MainControl is shown.</param>
        public MainViewModel(UserInformation currentUser, UserDatabase data, ViewModelHistory thisWindow)
        {
            this.currentUserInfo = currentUser;
            this.thisWindow      = thisWindow;

            this.operationModes.Add("Encrypt");
            this.operationModes.Add("Decrypt");
            this.ChosenMode = this.operationModes[0];

            this.hashAlgorithms.Add(new HashAlgorithmChoice("SHA256", SHA256.Create()));
            this.hashAlgorithms.Add(new HashAlgorithmChoice("MD5", MD5.Create()));
            this.ChosenHashAlgorithm = this.hashAlgorithms[0];

            this.encryptionAlgorithms.Add(new EncryptionAlgorithmChoice("AES", new AesMachine()));
            this.encryptionAlgorithms.Add(new EncryptionAlgorithmChoice("TripleDES", new TDesMachine()));
            this.encryptionAlgorithms.Add(new EncryptionAlgorithmChoice("Twofish", new TwofishMachine()));
            this.ChosenEncryptionAlgorithm = this.encryptionAlgorithms[0];

            this.allUsers.AddRange(data.GetAllUsers().Where((user) => user.Username != currentUser.Username));
        }
Esempio n. 3
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.";
     }
 }
        public ListUsersModule()
        {
            // add an after hook to send the user to access denied if they are NOT admin
            After += context =>
            {
                if (context.Response.StatusCode == HttpStatusCode.Forbidden)
                {
                    context.Response = Response.AsRedirect("/denied");
                }
            };
            this.RequiresAnyClaim(new[] { "admin" });

            Get["/users"] = _ =>
            {
                this.RequiresAuthentication();

                var users = UserDatabase.GetAllUsers();
                ViewBag.Title = "Application Users";
                return(View["Views/User/Users", users]);
            };
        }
        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.";
            }
        }
        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;
        }