private void btnUserManagement_Click(object sender, EventArgs e) { _globalState = State.UserManagement; StopTimer(); _formUserManagement.Show(); this.Hide(); }
private void btnOptionsSave_Click(object sender, EventArgs e) { if (_globalState == State.Initializing) { // TODO: Add capability for additional users with User.PermissionLevels = NONE // Save user preferences and information to database string name = tbxUserName.Text; string phoneNumber = tbxUserPhone.Text; User.PermissionLevels permissionLevel = (User.GetAll().Count() == 0) ? User.PermissionLevels.FULL : User.PermissionLevels.NONE; AuthenticationMethod primary = null; AuthenticationMethod secondary = null; switch (cbxPrimAuth.SelectedItem.ToString()) { case "Bluetooth": primary = (BluetoothDevice)cbxBTSelect1.SelectedItem; break; case "Card": primary = new Card(tbxCard.Text); break; } switch (cbxSecAuth.SelectedItem.ToString()) { case "Card": secondary = new Card(tbxCard.Text); break; case "Bluetooth": secondary = (BluetoothDevice)cbxBTSelect2.SelectedItem; break; case "PIN": secondary = new Pin(tbxPin.Text); break; } AuthenticationMethods authenticationMethods = new AuthenticationMethods(primary, secondary); User.Create(name, permissionLevel, phoneNumber, null, authenticationMethods); // Go to idle state _globalState = State.Idle; UpdateComponents(); tbxCard.Text = ""; } else if (_globalState == State.SecondFactor) { bool success = false; switch (_currentAuthSequence.NextAuthenticationMethod) { case Card card: success = _currentAuthSequence.Continue(new Card(tbxSecFactorPinOrCard.Text)); break; case Pin pin: success = _currentAuthSequence.Continue(new Pin(tbxSecFactorPinOrCard.Text)); break; case BluetoothDevice btDevice: success = bluetoothFound && _currentAuthSequence.Continue(btDevice); break; default: break; } if (success && _currentAuthSequence.NextAuthenticationMethod == null) { // Successful Authentication _currentUser = _currentAuthSequence.User; _globalState = State.Authenticated; UpdateComponents(); } else { if (--numTriesLeftSecondFactor == 0) { _globalState = State.AccessDenied; UpdateComponents(); } else { txtSecondFactorStatus.Visible = true; string pluralTries = numTriesLeftSecondFactor == 1 ? "try" : "tries"; txtSecondFactorStatus.Text = "Secondary authentication failed. You have " + numTriesLeftSecondFactor + " " + pluralTries + " left. Please try again."; tbxSecFactorPinOrCard.Text = ""; cardInput = ""; // just in case } } } else if (_globalState == State.Authenticated) { if (_currentUser.PermissionLevel == User.PermissionLevels.FULL) { _globalState = State.UserManagement; _formUserManagement.Show(); } else { _globalState = State.UserOptions; _formOptions.Show(); } UpdateComponents(); this.Hide(); } }