public User(string username, string salt, string hash, UserRole.Roles role, List <PhysicalAddress> macs) { Username = username; Salt = salt; Password = hash; Role = role; MACs = macs; }
private bool AllowGenOUI() { UserRole.Roles role = Utility.GetRole(AuthenticationStateTask !).Result; if (role != UserRole.Roles.Administrator) { return(false); } return(Common.ContraCoreClient.Connected && !Common.ContraCoreClient.GeneratingOUI); }
public static User Create(string username, string password, UserRole.Roles role, List <PhysicalAddress> macs) { (string salt, string hash) = Hash(password); User user = new User(username, salt, hash, role, macs); UserModel.Submit(user); return(user); }
protected override void OnInitialized() { ClientIP = HttpContextAccessor.HttpContext.Connection?.RemoteIpAddress.ToString(); _clientRole = Utility.GetRole(AuthenticationStateTask ?? throw new Exception("AuthenticationStateTask was not set")) .Result; _themeLoader = new ThemeLoader(LocalStorage, _configuration.ResourceManifests, "Dark"); _themeLoader.OnComplete += StateHasChanged; ContraWebAuthStateProvider.AuthenticationStateChanged += _ => _updateHeader.Trigger(); }
protected override void OnInitialized() { _clientRole = Utility.GetRole(AuthenticationStateTask ?? throw new ArgumentNullException()).Result; _newRule = new Infrastructure.Schema.Whitelist(); if (_clientRole != UserRole.Roles.Privileged && _clientRole != UserRole.Roles.Administrator) { throw new Exception(); } Log?fromLog = LogActionService.GetAndUnset(); if (fromLog != null) { Console.WriteLine("From log: " + fromLog.Question); string pattern = @"(?:^|.+\.)" + fromLog.Question.Replace(".", @"\.") + "$"; Rule().Pattern = pattern; } InitValidators(); InitInputs(); // _whitelistTable = new FlareTable <Infrastructure.Schema.Whitelist>( () => _clientRole == UserRole.Roles.Privileged ? WhitelistModel.List(ClientIP !) : WhitelistModel.List(), sessionStorage: SessionStorageService, identifier: "Rules.WhitelistTable", monospace: true); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.ID)); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.Pattern)); _whitelistTable.RegisterColumn(nameof(Infrastructure.Schema.Whitelist.Expires)); _whitelistTable.RegisterColumn("_Edit", sortable: false, filterable: false, displayName: "", width: "56px"); _whitelistTable.RegisterColumn("_Remove", sortable: false, filterable: false, displayName: "", width: "82px"); _whitelistTable.OnRowClick += whitelist => { }; BuildHeaders(); }
private async Task Submit() { if (_editing == null) { User newUser = UserController.Create(_newUsername, _newPassword, _newRole, new List <PhysicalAddress>()); _newUsername = ""; _newPassword = ""; _newRole = UserRole.Roles.Undefined; LoadUsers(); _userTable !.InvalidateData(); // _newRoleSelector!.InvalidateData(true); _newUserValidator.Validate(); } else { if (_editedRole != UserRole.Roles.Undefined) { _editing.Role = _editedRole; await UserModel.Update(_editing); } if (!string.IsNullOrEmpty(_editedPassword)) { await UserController.UpdatePassword(_editing, _editedPassword); } _editedRole = UserRole.Roles.Undefined; _editedPassword = ""; _editing = null; LoadUsers(); _userTable !.InvalidateData(); _newRoleSelector !.InvalidateData(true); _editUserValidator.Validate(); } Add(); }
protected override void OnInitialized() { LoadUsers(); _user = ((ContraWebAuthStateProvider)ContraWebAuthStateProvider).User; if (_user == null) { throw new Exception("User is not authenticated; access to this page should not have been permitted."); } _userTable = new FlareTable <User>( () => _users ?? new List <User>()); _userTable.RegisterColumn(nameof(User.Username)); _userTable.RegisterColumn(nameof(User.Role)); _userTable.RegisterColumn("_Edit", sortable: false, filterable: false, displayName: "", width: "56px"); _userTable.RegisterColumn("_Remove", sortable: false, filterable: false, displayName: "", width: "82px"); // _newUsernameDebouncer = new Debouncer <string>(value => { Console.WriteLine("--"); _newUsername = value; _newUserValidator.Validate(); InvokeAsync(StateHasChanged); }, _newUsername); _newPasswordDebouncer = new Debouncer <string>(value => { _newPassword = value; _newUserValidator.Validate(); InvokeAsync(StateHasChanged); }, _newPassword); // _newRoleSelector = new FlareSelector <string>( () => UserRole.Options(), false ); _newRoleSelector.OnSelect += selected => { _newRole = UserRole.NameToUserRole(selected.FirstOrDefault()?.ID); _newUserValidator.Validate(); InvokeAsync(StateHasChanged); }; _editedRoleSelector = new FlareSelector <string>( () => UserRole.Options(_editing?.Role), false, isDisabled: () => _editing?.Username == _user.Username); _editedRoleSelector.OnSelect += selected => { _editedRole = UserRole.NameToUserRole(selected.FirstOrDefault()?.ID); _editUserValidator.Validate(); InvokeAsync(StateHasChanged); }; // _newMACsSelector = new EditableList( validator: ValidateMAC, placeholder: "Add a MAC", transformer: Utility.FormatMAC ); _newMACsSelector.OnUpdate += macs => _user !.MACs = macs.Select(v => PhysicalAddress.Parse(Utility.CleanMAC(v))).ToList(); _editMACsSelector = new EditableList( validator: ValidateMAC, placeholder: "Add a MAC", transformer: Utility.FormatMAC ); _editMACsSelector.OnUpdate += macs => _editing !.MACs = macs.Select(v => PhysicalAddress.Parse(Utility.CleanMAC(v))).ToList(); // _newUserValidator = new Validator <ValidationResult>(() => { if (string.IsNullOrEmpty(_newUsername)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Username is required") } } ; User?found = UserModel.Find(_newUsername).Result; if (found != null) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Username is already registered") } } ; if (string.IsNullOrEmpty(_newPassword)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Password is required") } } ; if (_newRole == UserRole.Roles.Undefined || _newRole == UserRole.Roles.Restricted) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Role is invalid") } } ; return(new[] { new Validation <ValidationResult>(ValidationResult.Valid, "User is valid") }); }); _editUserValidator = new Validator <ValidationResult>(() => { // if (string.IsNullOrEmpty(_editedPassword)) // return new Validation(ValidationResult.Invalid, "Password is required"); if (_editedRole == UserRole.Roles.Undefined || _editedRole == UserRole.Roles.Restricted) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Role is invalid") } } ; return(new[] { new Validation <ValidationResult>(ValidationResult.Valid, "Edits are valid") }); }); _newUserValidator.Validate(); // BuildHeaders(); }
private void GetClientRole(Task <AuthenticationState> authState) { _clientRole = Utility.GetRole(authState).Result; }
protected override void OnInitialized() { _clientRole = Utility.GetRole(AuthenticationStateTask ?? throw new ArgumentNullException()).Result; _newRule = new Infrastructure.Schema.Blacklist(); Log?fromLog = LogActionService.GetAndUnset(); if (fromLog != null) { Console.WriteLine("From log: " + fromLog.Question); string pattern = @"(?:^|.+\.)" + fromLog.Question.Replace(".", @"\.") + "$"; _newRule.Pattern = pattern; } _validator = new Validator <ValidationResult>(); _validator.Register("Pattern", () => { if (_clientRole != UserRole.Roles.Administrator) { return new[] { new Validation <ValidationResult>(ValidationResult.Warning, "You are not permitted to create blacklist rules") } } ; if (string.IsNullOrEmpty(Rule().Pattern)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Required") } } ; if (!Utility.ValidateRegex(Rule().Pattern)) { return new[] { new Validation <ValidationResult>(ValidationResult.Invalid, "Invalid regular expression") } } ; return(new[] { new Validation <ValidationResult>(ValidationResult.Valid, "Valid") }); }); _patternChangeDebouncer = new Debouncer <string>(pattern => { _validator !.Validate(); _onInputValidation.Trigger(); InvokeAsync(StateHasChanged); }, "", 200); _validator.Validate(); Task.Run(() => { try { BuildBlacklistTable(); } catch (Exception e) { Console.WriteLine(e); } }); // BuildHeaders(); }