Esempio n. 1
0
        private static void insertMeasurementTest()
        {
            DBConnect db = new DBConnect();
            Measurement m = new Measurement();

            db.SaveMeasurement(m, db.getNewTrainingSessionId(1), 1);
        }
Esempio n. 2
0
        //private Boolean isLoggedIn;

        public ClientHandler(TcpClient client)
        {
            _tcpclient = client;
            var certificate = new X509Certificate2(Resources._23tia5_centificate, "AvansHogeschool23ti2a5");
            //var certificate = new X509Certificate2(Resources.invalid_certificate, "apeture");

            _sslStream = new SslStream(_tcpclient.GetStream());
            _sslStream.AuthenticateAsServer(certificate);
            _totalBuffer = new List<byte>();
            _database = new DBConnect();
            var thread = new Thread(ThreadLoop);
            thread.Start();

        }
Esempio n. 3
0
        public static Boolean Authenticate(String username, String passhash, ClientHandler handler)
        {
            //check that user and passhash are valid.
            var database = new DBConnect();
            var tuple = database.ValidateUser(username, passhash, true);

            if (!tuple.Item1) // if the tuple.Item1 equals false, return false and exit this method.
                return false;

            //Creating the hash (AuthToken)
            //1. Prepare the string for hashing (user-passhash-milliseconds_since_epoch)
            var millis = DateTime.Now.ToUniversalTime().Subtract(
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                ).TotalMilliseconds;
            var aboutToHash = String.Format("{0}-{1}-{2}", username, passhash, millis);

            //2. Hash the string.
            var hash = Hashing.CreateSHA256(aboutToHash);

            //3. Create the user :D
            var user = database.getUser(username);

            //if user == null, exit this method!
            if (user == null) return false;

            user.AuthToken = hash;

            //4. Remove the user if existing in the list.
            var searchQuery =
                from kvPair in AuthUsers
                where kvPair.Key.Username == username
                select kvPair.Key;

            // Above query (searchQuery) is exactly the same as:
            // var search2 = AuthUsers
            //     .Where(kvPair => kvPair.Key.Username == username)
            //     .Select(kvPair => kvPair.Key); 

            foreach (var key in searchQuery)
            {
                ClientHandler tempClientHandler;
                AuthUsers.TryRemove(key, out tempClientHandler);
            }

            //5. Add the user to the AuthUsers class.
            AuthUsers.GetOrAdd(user, handler);

            return true;
        }
Esempio n. 4
0
 public DBIntegration()
 {
     db = new DBConnect("root", "", "localhost", "Healthcare_test");
     exterminateDB();
     string dbStructureSQL;
     try
     {
         using (StreamReader sr = new StreamReader("deb58589n5_healthcare.mysql"))
         {
             dbStructureSQL = sr.ReadToEnd();
             MySqlCommand createDB = new MySqlCommand(dbStructureSQL, db.Connection);
             createDB.ExecuteNonQuery();
         }
     }
     catch (MySqlException e)
     {
         Console.WriteLine(e.Message);
         throw;
     }
 }
Esempio n. 5
0
        private void _quitButton_Click(object sender, EventArgs e)
        {

            //this.Hide();            
            //_controller.UpdatedList -= updateGUI;
            if (_controller != null)
                _controller.Stop();

            if (isSpecialist)
            {
                TCPController.Send(new NotifyPacket(NotifyPacket.Subject.StopTraining, client.NonNullId.ToString(),
                    Settings.GetInstance().authToken));
                this.Hide();

                DBConnect db = new DBConnect();

                int id;
                if (isSpecialist)
                    id = client.NonNullId;
                else
                {
                    id = Settings.GetInstance().CurrentUser.NonNullId;
                }

                GraphResultUI g = new GraphResultUI(db.getMeasurementsOfUser(id.ToString(), currentTraingId.ToString()));
                g.Show();
            }

            _inTraining = false;


        }
Esempio n. 6
0
 public Packets()
 {
      db = new DBConnect();
 }
Esempio n. 7
0
        private void _createButton_Click(object sender, EventArgs e)
        {
            _connection = new DBConnect();

            const string pleaseFillIntext = "Please fill in all fields";
            if(string.IsNullOrEmpty(_nameBox.Text) || string.IsNullOrEmpty(_surnameBox.Text) || !_genderMaleRadioButton.Checked && !_genderFemaleRadioButton.Checked ){
                MessageBox.Show(pleaseFillIntext);
                return;
            }
            else if (clientRadioButton.Checked && String.IsNullOrEmpty(_lengthBox.Text) || clientRadioButton.Checked && string.IsNullOrEmpty(_weightBox.Text))
            {
                MessageBox.Show(pleaseFillIntext);
                return;
            }

            var gender = _genderMaleRadioButton.Checked ? "m" : "f";

            bool succes;

            //TODO create user with given data, save into db
            if (clientRadioButton.Checked)
            {

                Client client = new Client()
                {

                    AuthToken = "",
                    DateOfBirth = dateOfBirthPicker.Value,
                    Gender = gender,
                    Weight = Decimal.Parse(_weightBox.Text),
                    Lenght = Decimal.Parse(_lengthBox.Text),
                    Name = _nameBox.Text,
                    Surname = _surnameBox.Text,
                    Username = Usernamebox.Text,
                    PasswordToBeSaved = passwordBox.Text


                };

                succes = _connection.saveUser(client);
            }
            else
            {

                Specialist specialist = new Specialist()
                {
                    AuthToken = "",
                    DateOfBirth = dateOfBirthPicker.Value,
                    Name = _nameBox.Text,
                    Gender = gender,
                    PasswordToBeSaved = passwordBox.Text,
                    Username = Usernamebox.Text,
                    Surname = _surnameBox.Text
                };

                succes = _connection.saveUser(specialist);
            }
            
            if (succes)
            {
                MessageBox.Show("Success: the user has been added.");
                this.Close();
            }
            else
            {
                MessageBox.Show("Could not add the user.");
            }

        }