public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (UserGroups.Any() == false) { yield return(new ValidationResult("A user must be assigned to at least one group", new[] { "UserGroups" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (UserGroups.Any() == false) { yield return(new ValidationResult("A user must be assigned to at least one group", new[] { "UserGroups" })); } if (Current.Configs.Settings().Security.UsernameIsEmail == false && Username.IsNullOrWhiteSpace()) { yield return(new ValidationResult("A username cannot be empty", new[] { "Username" })); } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (UserGroups.Any() == false) { yield return(new ValidationResult("A user must be assigned to at least one group", new[] { nameof(UserGroups) })); } var securitySettings = validationContext.GetRequiredService <IOptionsSnapshot <SecuritySettings> >(); if (securitySettings.Value.UsernameIsEmail == false && Username.IsNullOrWhiteSpace()) { yield return(new ValidationResult("A username cannot be empty", new[] { nameof(Username) })); } }
/// <summary> /// </summary> /// <param name="role"></param> /// <param name="forAll">true在Roles,UserGroup,false,只在for中查找</param> /// <returns></returns> public virtual bool InRole(Role role, bool forAll) { if (LoginId == AdminLoginId) { return(true); } bool result = base.InRole(role); if (result) { return(true); } if (!forAll) { return(false); } return(UserGroups.Any(ug => ug.InRole(role))); }
/// <summary> /// Assign / Remove groups /// </summary> /// <param name="groups">Groups id</param> /// <param name="groupEntities">Group entities</param> public void EditGroups(IEnumerable <int> groups, List <Group.Group> groupEntities) { if (Root) { throw new ForbiddenOperationDomainException("Root user"); } var groupIds = groups as int[] ?? groups.ToArray(); foreach (var groupId in groupIds) { var group = groupEntities.FirstOrDefault(g => g.Id == groupId); // Skip if the group to add no exists in the context if (group == null) { continue; } // Skip if the group is just assigned if (UserGroups.Any(i => i.GroupId == groupId)) { continue; } UserGroups.Add( new UserGroup { GroupId = group.Id, UserId = Id }); } // Remove deleted groups foreach (var userGroup in UserGroups.ToArray()) { if (!groupIds.Contains(userGroup.GroupId)) { UserGroups.Remove(userGroup); } } }
public bool HasRight(string rightName) { return(Role == UserRole.Administrator || UserGroups != null && UserGroups.Any(e => e.Group.HasRight(rightName))); }