Example #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            User tempUser = new UserSyncer().WebLogin(Username.Text, Password.Password);

            if (tempUser != null)
            {
                UserPrefs.SetUser(tempUser, true);
                this.AddPasswordHash(Username.Text, PasswordHash.Hash(Password.Password));
                MainWindow mainWindow = ((MainWindow)Application.Current.MainWindow);
                this.Close();
            }
            else
            {
                if (this.CheckPasswordLocal(Username.Text, Password.Password))
                {
                    UserPrefs.SetUser(new Users.User(Username.Text, Password.Password, Username.Text), false);

                    MainWindow mainWindow = ((MainWindow)Application.Current.MainWindow);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Wrong username or password");
                }
            }
        }
        private void btnCreateUser_Click(object sender, RoutedEventArgs e)
        {
            string userName = this.userNameBox.Text;
            string password = this.passwordBox.Password;
            string name     = this.nameBox.Text;
            bool   isAdmin  = (bool)this.isAdminCheck.IsChecked;

            UserSyncer userSyncer = new UserSyncer();
            User       user       = userSyncer.WebCreateUser(userName, password, name, isAdmin);

            if (user != null)
            {
                UserPrefs.AddUser(user);
                this.Close();
            }
            else
            {
                MessageBox.Show("User already exists!");
            }
        }
Example #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            UserSyncer userSyncer = new UserSyncer();

            //TODO: check the network to make sure we've got the right credentials. If there's no network connection
            //check against a saved file that has hashed passwords or something.
            User tempUser = userSyncer.WebLogin(Username.Text, Password.Password);

            if (tempUser != null)
            {
                UserPrefs.OnLoad();
                MainWindow mainWindow = ((MainWindow)Application.Current.MainWindow);
                UserPrefs.SetUser(tempUser, true);
                mainWindow.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Wrong username or password");
            }
        }
Example #4
0
        private static void TestForm()
        {
            CaseFile caseFile = new CaseFile("case00001", "Steve's assisted living", 00004);
            Report   report   = caseFile.AddReport("kenny00001", "kenny");
            Form     form     = report.AddForm(new Form("formA"));
            User     testUser;


            Console.WriteLine(caseFile);

            Console.WriteLine("Testing users");
            UserSyncer userSyncer = new UserSyncer();

            userSyncer.CreateUser("tester", "tpassword", "Bob", false);
            Console.WriteLine("Testing valid login info");
            testUser = userSyncer.Login("tester", "tpassword");
            Console.WriteLine("Testing invalid login info");
            userSyncer.Login("tester", "asd");
            Console.WriteLine("Testing colliding usernames user creation");
            userSyncer.CreateUser("tester", "tPassword", "Bill", true);

            CaseFileSyncer syncer = new CaseFileSyncer();

            Console.WriteLine("Testing inserting case file into database");
            //syncer.SyncCaseFile(caseFile, testUser);
            caseFile.Sync(testUser);
            Console.WriteLine("Testing updating case file already in database");
            CaseFile caseFile2 = new CaseFile("case00001", "Bob's assisted living", 00004);

            //syncer.SyncCaseFile(caseFile2, testUser);
            caseFile2.Sync(testUser);
            CaseFile caseFile3 = new CaseFile(caseFile2.caseID, "Bob's existing living", 00004);

            syncer.UpdateCaseFile(caseFile3);

            CaseFile databaseCaseFile = new CaseFile("14", "invalid", -1);

            //databaseCaseFile = syncer.SyncCaseFile(databaseCaseFile, testUser);
            databaseCaseFile.Sync(testUser);
            Console.WriteLine(databaseCaseFile);



            string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testXML");

            XmlSerializer ser = new XmlSerializer(caseFile.GetType());

            using (TextWriter writer = new StreamWriter(dir + @"\groupTest.xml"))
            {
                ser.Serialize(writer, caseFile);
            }


            Console.WriteLine("\n    >done!");
            Console.WriteLine("    >Now reading from file!");


            CaseFile readField;

            using (TextReader reader = new StreamReader(dir + @"\groupTest.xml"))
            {
                readField = (CaseFile)ser.Deserialize(reader);
            }

            Console.WriteLine(readField);
        }