Example #1
0
		private void detach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Group = null;
		}
Example #2
0
		private void attach_Users(User entity)
		{
			this.SendPropertyChanging();
			entity.Group = this;
		}
 private IList<RoleInformation> GetRoles(User user, IList<RoleInformation> roles,
     IList<int> visitedUsers)
 {
     var localRoles = user.User2Roles.Select(v => new RoleInformation { RoleName = v.Role.Name, Access = v.Access });
     foreach (var localRole in localRoles)
     {
         var childRole = roles.FirstOrDefault(v => v.RoleName == localRole.RoleName);
         if (childRole == null)
         {
             roles.Add(localRole);
             continue;
         }
         if (!childRole.Access.GetValueOrDefault(true))
             continue;
         childRole.Access = localRole.Access;
     }
     foreach (var parentUser in GetGroups(user, visitedUsers))
     {
         visitedUsers.Add(parentUser.Id);
         roles = GetRoles(parentUser, roles, visitedUsers);
     }
     return roles;
 }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion,
            string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            if (string.IsNullOrEmpty(username))
            {
                status = MembershipCreateStatus.InvalidUserName;
                return null;
            }

            if (string.IsNullOrEmpty(email))
            {
                status = MembershipCreateStatus.InvalidEmail;
                return null;
            }

            if (!string.IsNullOrEmpty(password) && password.Length < MinRequiredPasswordLength)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            var repository = new SecurityRepository();

            if (repository.TestUserByLogin(username))
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }

            if (repository.TestUserByEmail(email))
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var salt = SaltGenerator.GenerateSalt();

            var account = new User
            {
                Login = username,
                EMail = email,
                Salt = salt,
                FirstName = username,
                LastName = username,
                PasswordQuestion = passwordQuestion,
                PasswordAnswer = passwordAnswer
            };

            repository.SaveUser(account);

            var user = (AccountMembershipUser)GetUser(username, false);
            if (user != null)
            {
                user.SavePassword(password);
                status = MembershipCreateStatus.Success;
            }
            else
                status = MembershipCreateStatus.ProviderError;
            return user;
        }
 private IEnumerable<User> GetGroups(User user, IList<int> visitedUsers)
 {
     return user.ParentUsers.Where(v => !visitedUsers.Contains(v.ParentUserId))
         .Select(v => v.ParentUser);
 }