Esempio n. 1
0
        public async Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken)
        {
            var task = Task.Factory.StartNew(() =>
            {
                var userContract = new PrivateUserContract
                {
                    UserName           = user.UserName,
                    Email              = user.Email,
                    FirstName          = user.FirstName,
                    LastName           = user.LastName,
                    CreateTime         = user.CreateTime,
                    PasswordHash       = user.PasswordHash,
                    CommunicationToken = user.CommunicationToken
                };

                using (var client = m_communication.GetEncryptedClient())
                {
                    var result              = client.CreateUser(userContract);
                    user.CreateTime         = result.CreateTime;
                    user.CommunicationToken = result.CommunicationToken;
                    user.Id = result.Id.ToString();
                    return(IdentityResult.Success);
                }
            });

            return(await task);
        }
Esempio n. 2
0
        public PrivateUserContract CreateLocalUser(PrivateUserContract user)
        {
            var now = DateTime.UtcNow;
            var defaultFavoriteLabel = new FavoriteLabel
            {
                Name        = DefaultFavoriteLabelName,
                Color       = DefaultFavoriteLabelColor,
                IsDefault   = true,
                LastUseTime = now
            };
            var dbUser = new User
            {
                UserName                     = user.UserName,
                Email                        = user.Email,
                FirstName                    = user.FirstName,
                LastName                     = user.LastName,
                CreateTime                   = now,
                PasswordHash                 = user.PasswordHash,
                AuthenticationProvider       = AuthenticationProvider.ItJakub,
                CommunicationToken           = m_communicationTokenGenerator.GetNewCommunicationToken(),
                CommunicationTokenCreateTime = now,
                Groups                       = new List <Group> {
                    m_defaultMembershipProvider.GetDefaultRegisteredUserGroup(), m_defaultMembershipProvider.GetDefaultUnRegisteredUserGroup()
                },
                FavoriteLabels = new List <FavoriteLabel> {
                    defaultFavoriteLabel
                }
            };

            defaultFavoriteLabel.User = dbUser;

            var userId = m_userRepository.Create(dbUser);

            return(GetPrivateUserDetail(userId));
        }
Esempio n. 3
0
        public void GetGroupsByUserTest()
        {
            var newUserContract = new PrivateUserContract
            {
                FirstName = "Test",
                LastName  = "User",
                Email     = string.Format("test@{0}.test", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var user       = m_userManager.CreateLocalUser(newUserContract);
            var groupName  = string.Format("TestGroup{0}", Guid.NewGuid());
            var groupName2 = string.Format("TestGroup{0}", Guid.NewGuid());
            var group      = m_permissionManager.CreateGroup(groupName, "Just testing group with member");
            var group2     = m_permissionManager.CreateGroup(groupName2, "Just testing group with member");

            var firstMemberContract = new PrivateUserContract
            {
                FirstName = "First",
                LastName  = "Member",
                Email     = string.Format("first@{0}.member", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var firstMember = m_userManager.CreateLocalUser(firstMemberContract);

            var secondMemberContract = new PrivateUserContract
            {
                FirstName = "Second",
                LastName  = "Member",
                Email     = string.Format("second@{0}.member", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var secondMember = m_userManager.CreateLocalUser(secondMemberContract);

            m_permissionManager.AddUserToGroup(firstMember.Id, group.Id);

            m_permissionManager.AddUserToGroup(firstMember.Id, group2.Id);

            m_permissionManager.AddUserToGroup(secondMember.Id, group.Id);

            var groupsForFirstMember = m_permissionManager.GetGroupsByUser(firstMember.Id)
                                       .Where(x => x.Description != "Default user group");

            var groupsForSecondMember = m_permissionManager.GetGroupsByUser(secondMember.Id)
                                        .Where(x => x.Description != "Default user group");

            Assert.IsNotNull(groupsForFirstMember);
            Assert.AreEqual(2, groupsForFirstMember.Count());

            Assert.IsNotNull(groupsForSecondMember);
            Assert.AreEqual(1, groupsForSecondMember.Count());
        }
Esempio n. 4
0
        public void CreateUserTest()
        {
            var guid            = Guid.NewGuid();
            var newUserContract = new PrivateUserContract
            {
                FirstName = "Test",
                LastName  = "User",
                Email     = string.Format("test@{0}.test", guid),
                UserName  = string.Format("user{0}", guid)
            };

            var user = m_userManager.CreateLocalUser(newUserContract);

            Assert.IsNotNull(user);
        }
Esempio n. 5
0
        public void CreateGroupTest()
        {
            var newUserContract = new PrivateUserContract
            {
                FirstName = "Test",
                LastName  = "User",
                Email     = string.Format("test@{0}.test", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var user      = m_userManager.CreateLocalUser(newUserContract);
            var groupName = string.Format("TestGroup{0}", Guid.NewGuid());
            var group     = m_permissionManager.CreateGroup(groupName, "Just testing creating group");

            Assert.IsNotNull(group);
        }
Esempio n. 6
0
        public void RemoveMemberFromGroupTest()
        {
            var newUserContract = new PrivateUserContract
            {
                FirstName = "Test",
                LastName  = "User",
                Email     = string.Format("test@{0}.test", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var user      = m_userManager.CreateLocalUser(newUserContract);
            var groupName = string.Format("TestGroup{0}", Guid.NewGuid());
            var group     = m_permissionManager.CreateGroup(groupName, "Just testing group with member");

            var firstMemberContract = new PrivateUserContract
            {
                FirstName = "First",
                LastName  = "Member",
                Email     = string.Format("first@{0}.member", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var firstMember = m_userManager.CreateLocalUser(firstMemberContract);

            var secondMemberContract = new PrivateUserContract
            {
                FirstName = "Second",
                LastName  = "Member",
                Email     = string.Format("second@{0}.member", Guid.NewGuid()),
                UserName  = Guid.NewGuid().ToString()
            };

            var secondMember = m_userManager.CreateLocalUser(secondMemberContract);

            m_permissionManager.AddUserToGroup(firstMember.Id, group.Id);

            m_permissionManager.AddUserToGroup(secondMember.Id, group.Id);

            m_permissionManager.RemoveUserFromGroup(firstMember.Id, group.Id);

            var groupDetails = m_permissionManager.GetGroupDetail(group.Id);

            Assert.IsNotNull(groupDetails);
            Assert.IsNotNull(groupDetails.Members);
            Assert.AreEqual(1, groupDetails.Members.Count);
            Assert.AreEqual(secondMember.Id, groupDetails.Members.First().Id);
        }
Esempio n. 7
0
 public PrivateUserContract CreateUser(PrivateUserContract user)
 {
     try
     {
         return(Channel.CreateUser(user));
     }
     catch (CommunicationException ex)
     {
         if (m_log.IsErrorEnabled)
         {
             m_log.ErrorFormat("{0} failed with: {1}", GetCurrentMethod(), ex);
         }
         throw;
     }
     catch (TimeoutException ex)
     {
         if (m_log.IsErrorEnabled)
         {
             m_log.ErrorFormat("{0} timeouted with: {1}", GetCurrentMethod(), ex);
         }
         throw;
     }
 }
Esempio n. 8
0
 public PrivateUserContract CreateUser(PrivateUserContract user)
 {
     return(m_userManager.CreateLocalUser(user));
 }