Esempio n. 1
0
        private void removeUserFromRole(CouchDbMembershipUser user, string role)
        {
            var roleList = new List <string>(user.Roles);

            roleList.Remove(role);

            user.Roles = roleList.ToArray();
            user.Save();
        }
Esempio n. 2
0
 private void addUserToRoles(CouchDbMembershipUser user, string[] roles)
 {
     var currentRoles = new List<string>(user.Roles);
     foreach (var role in roles)
     {
         if (!currentRoles.Contains(role)) currentRoles.Add(role);
     }
     user.Roles = currentRoles.ToArray();
     user.Save();
 }
        public CouchDbMembershipUser GetUserByEmail(string email)
        {
            dynamic results = base.GetByKey(designDocument, view_all_by_email, email).rows;

            if (results.Length == 0)
            {
                return(null);
            }

            return(CouchDbMembershipUser.FromDynamicDbResponse(results[0].value)); // TODO Vale con devolver solo el primero?
        }
        public void GivenIHaveAValidCouchDbMembershipUserWithRolesAssigned()
        {
            userName = Guid.NewGuid().ToString();
            user = Membership.CreateUser(userName, Guid.NewGuid().ToString()) as CouchDbMembershipUser;

            Roles.CreateRole("admin");
            Roles.CreateRole("webuser");

            Roles.AddUserToRole(userName, "admin");
            Roles.AddUserToRole(userName, "webuser");
        }
Esempio n. 5
0
        private void addUserToRoles(CouchDbMembershipUser user, string[] roles)
        {
            var currentRoles = new List <string>(user.Roles);

            foreach (var role in roles)
            {
                if (!currentRoles.Contains(role))
                {
                    currentRoles.Add(role);
                }
            }
            user.Roles = currentRoles.ToArray();
            user.Save();
        }
        public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
        {
            var db = new CouchDbMembershipUserRepository(couchDbServerName, couchDbServerPort, couchDbDatabaseName);

            totalRecords = 0;

            var returnCollection = new MembershipUserCollection();

            foreach (dynamic mu in db.GetAll())
            {
                returnCollection.Add(CouchDbMembershipUser.FromDynamicDbResponse(mu.value));
            }

            return(returnCollection);
        }
        public void GivenIHaveAValidUserWithRolesAssigned()
        {
            userName = Guid.NewGuid().ToString();
            user = Membership.CreateUser(userName, Guid.NewGuid().ToString()) as CouchDbMembershipUser;

            Roles.CreateRole("admin");
            Roles.CreateRole("webuser");

            Roles.AddUserToRole(userName, "admin");
            Roles.AddUserToRole(userName, "webuser");

            var userRoles = new List<string>(Roles.GetRolesForUser(userName));

            Assert.IsTrue(userRoles.Contains("admin"));
        }
Esempio n. 8
0
        public override string[] GetUsersInRole(string roleName)
        {
            var users = getMembershipRepository().GetUsersByRole(roleName);

            var db = getMembershipRepository();

            var userNamesList = new List <String>();

            foreach (dynamic mu in db.GetUsersByRole(roleName))
            {
                userNamesList.Add(CouchDbMembershipUser.FromDynamicDbResponse(mu.value).UserName);
            }

            return(userNamesList.ToArray());
        }
Esempio n. 9
0
        internal static CouchDbMembershipUser FromDynamicDbResponse(dynamic dbUser)
        {
            var user = new CouchDbMembershipUser(dbUser.ProviderName,
                                                 dbUser.UserName, dbUser.ProviderUserKey, dbUser.Email,
                                                 dbUser.PasswordQuestion, dbUser.Comment, dbUser.IsApproved,
                                                 dbUser.IsLockedOut,
                                                 DateTime.Parse(dbUser.CreationDate),
                                                 DateTime.Parse(dbUser.LastLoginDate),
                                                 DateTime.Parse(dbUser.LastActivityDate),
                                                 DateTime.Parse(dbUser.LastPasswordChangedDate),
                                                 DateTime.Parse(dbUser.LastLockoutDate));

            user._id          = dbUser._id;
            user._rev         = dbUser._rev;
            user.type         = dbUser.type;
            user.PasswordHash = dbUser.PasswordHash;
            user.Roles        = Array.ConvertAll((object[])dbUser.Roles, (item => (string)item));;

            return(user);
        }
        public void GivenIHaveAValidRoleAssignedToAUser()
        {
            roleName = "RoleToAssignAndRemoveFromUser";

            Roles.CreateRole(roleName);

            var users = Membership.GetAllUsers();
            var rnd = new Random().Next(users.Count);
            int i = 0;
            foreach (var u in Membership.GetAllUsers())
            {
                i++;
                if (i == rnd)
                {
                    user = u as CouchDbMembershipUser;
                    break;
                }
            }
            Roles.AddUserToRole(user.UserName, roleName);
        }
        public override MembershipUser CreateUser(string userName,
                                                  string password, string email, string passwordQuestion, string passwordAnswer,
                                                  bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(userName, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            if (requiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }

            var user = GetUser(userName, false);

            if (user != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return(null);
            }

            var membershipUser = new CouchDbMembershipUser(providerName, userName, Guid.NewGuid().ToString(), email,
                                                           passwordQuestion, String.Empty, isApproved, false, DateTime.Now, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);

            membershipUser.PasswordHash = new PasswordManager().EncodePassword(password, MembershipPasswordFormat.Hashed, machineKeySection.ValidationKey);

            SaveNewUser(membershipUser);

            status = MembershipCreateStatus.Success;
            return(membershipUser);
        }
 private void DeleteUser(CouchDbMembershipUser user)
 {
     getRepository().Delete(user.ProviderUserKey.ToString());
 }
 private void SaveUser(CouchDbMembershipUser user)
 {
     getRepository().SaveWithId(user.ProviderUserKey.ToString(), user);
 }
 private void SaveUser(CouchDbMembershipUser user)
 {
     getRepository().SaveWithId(user.ProviderUserKey.ToString(), user);
 }
 private void DeleteUser(CouchDbMembershipUser user)
 {
     getRepository().Delete(user.ProviderUserKey.ToString());
 }
Esempio n. 16
0
        private void removeUserFromRole(CouchDbMembershipUser user, string role)
        {
            var roleList = new List<string>(user.Roles);

            roleList.Remove(role);

            user.Roles = roleList.ToArray();
            user.Save();
        }
        public override MembershipUser CreateUser(string userName, 
            string password, string email, string passwordQuestion, string passwordAnswer, 
            bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(userName, password, true);
            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (requiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            var user = GetUser(userName, false);
            if (user != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                return null;
            }

            var membershipUser = new CouchDbMembershipUser(providerName, userName, Guid.NewGuid().ToString(), email, 
                passwordQuestion, String.Empty, isApproved, false, DateTime.Now, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue);

            membershipUser.PasswordHash = new PasswordManager().EncodePassword(password, MembershipPasswordFormat.Hashed, machineKeySection.ValidationKey);

            SaveNewUser(membershipUser);

            status = MembershipCreateStatus.Success;
            return membershipUser;
        }
Esempio n. 18
0
        internal static CouchDbMembershipUser FromDynamicDbResponse(dynamic dbUser)
        {
            var user = new CouchDbMembershipUser(dbUser.ProviderName, 
                dbUser.UserName, dbUser.ProviderUserKey, dbUser.Email, 
                dbUser.PasswordQuestion, dbUser.Comment, dbUser.IsApproved, 
                dbUser.IsLockedOut, 
                DateTime.Parse(dbUser.CreationDate), 
                DateTime.Parse(dbUser.LastLoginDate), 
                DateTime.Parse(dbUser.LastActivityDate),
                DateTime.Parse(dbUser.LastPasswordChangedDate),
                DateTime.Parse(dbUser.LastLockoutDate));

            user._id = dbUser._id;
            user._rev = dbUser._rev;
            user.type = dbUser.type;
            user.PasswordHash = dbUser.PasswordHash;
            user.Roles = Array.ConvertAll((object[])dbUser.Roles, (item => (string)item)); ;
            
            return user;
        }
 public void GivenIHaveAValidCouchDbMembershipUser()
 {
     user = Membership.CreateUser(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) as CouchDbMembershipUser;
 }