Exemplo n.º 1
0
        //http get Usertag request
        public static async Task <ReturnObject> GetUserTagAsync(String path)
        {
            ReturnObject user = null;
            //String nuidAuthenticationString = "";
            HttpResponseMessage response = await httpClient.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                user = await response.Content.ReadAsAsync <ReturnObject>();
            }
            return(user);
        }
Exemplo n.º 2
0
        //===================\\
        //   The functions   \\
        //===================\\
        #region Functions

        //checks if the entered nuid exists
        private async void nuidValidation(String pNuid)
        {
            _httpRequest = new HttpRequest("UserTagItems", pNuid);
            ReturnObject returnedObject = await HttpRequest.GetUserTagAsync(_httpRequest.createUrl());

            _userTagView = returnedObject.ReturnUserTag;

            if (returnedObject.StatusCode == 3)//if pass does not exist
            {
                //the new client
                UserTag newUserTag = new UserTag {
                    PassId = pNuid
                };
                Client newClient = new Client();
                _currentClient = newClient;

                //opens a new form to add the new user
                using (SetClientDialogBox clientForm = new SetClientDialogBox(_currentClient, newUserTag))
                {
                    //opens a new form to add the new client to the database
                    if (clientForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        myPort.WriteLine("R");
                    }
                }
            }
            else if (returnedObject.StatusCode == 0)//if the pass exists and is not blocked
            {
                _httpRequest   = new HttpRequest("ClientItems", _userTagView.UserTagId.ToString());
                _currentClient = await HttpRequest.GetClientAsync(_httpRequest.createUrl());

                //sends command to arduino to read the keypad
                myPort.WriteLine("P");
                _loggedOut = false;
                //update the shown text on screen
                updateText(_currentClient);
            }
            else if (returnedObject.StatusCode == 2)//the user pass is blocked
            {
                //error, pass is blocked
                Helper.showMessage("Helaas, Uw pas is geblokkeerd", MessageBoxIcon.Error);
                myPort.WriteLine("R");
            }
            //update the form
            if (_currentClient != null)
            {
                UpdateForm(_currentClient);
            }
        }
Exemplo n.º 3
0
        private async void btnOk_Click(object sender, EventArgs e)
        {
            Boolean validInput = false;

            checkInput = new CheckValidUserInput(_currentClient);

            if (!string.IsNullOrWhiteSpace(tbUserName.Text) && !string.IsNullOrWhiteSpace(tbUserPassword.Text))
            {
                if (tbUserPassword.Text.Length == 4)
                {
                    validInput = true;
                }
            }
            else
            {
                validInput = false;
            }

            validInput = checkInput.validInput(tbUserPassword.Text, validInput);

            if (validInput && checkInput.validUserInput)
            {
                HttpRequest httpRequest;
                username = tbUserName.Text;
                password = new string(checkInput.checkInput);
                password = password.Replace("\n", "");
                password = password.Replace("\r", "");

                //create a new usertag
                _newUserId.Password = password;
                httpRequest         = new HttpRequest("UserTagItems");
                Object response = await HttpRequest.CreateAsync(_newUserId, httpRequest.createUrl());

                //get the new usertag
                httpRequest = new HttpRequest("UserTagItems", _newUserId.PassId);
                ReturnObject returnedObject = await HttpRequest.GetUserTagAsync(httpRequest.createUrl());

                UserTagViewModel createdUser = returnedObject.ReturnUserTag;

                //create a new user, and link the user and the usertag with the usertagId
                _currentClient.Name      = username;
                _currentClient.UserTagId = createdUser.UserTagId;
                httpRequest = new HttpRequest("ClientItems");
                response    = await HttpRequest.CreateAsync(_currentClient, httpRequest.createUrl());

                Helper.showMessage("U bent succesvol toegevoegd.");

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                if (!validInput)
                {
                    if (!checkInput.validUserInput && checkInput.inputLength == 4)
                    {
                        Helper.showMessage("Uw wachtwoord mag alleen bestaan uit: '0, 1, 2, 3, 4, 5, 6, 7, 8, 9' ", MessageBoxIcon.Error);
                    }
                    else if (checkInput.inputLength < 4 || checkInput.inputLength > 4)
                    {
                        Helper.showMessage("Uw wachtwoord moet bestaan uit 4 karakters. U hebt er nu: " + checkInput.inputLength, MessageBoxIcon.Error);
                    }
                    else
                    {
                        Helper.showMessage("Gelieve AL de velden invullen.", MessageBoxIcon.Error);
                    }
                }
            }
        }