Exemple #1
0
        public static void UserAdd()
        {
            UserArgs args = (UserArgs)PSCDialog.DataShare;
            User     user = ((UserArgs)PSCDialog.DataShare).User;
            CustomMembershipProvider customMembership = new CustomMembershipProvider();

            user.Password = customMembership.TransformPassword(user.Password);
            bool validate = customMembership.ValidateUserNameAndEmail(user);

            if (user.Name.Trim() == "" || validate == false)
            {
                return;
            }
            UserList.AddDB(user);
            // roles of user
            UserInRoleCollection userInRoleCollection = new UserInRoleCollection();
            UserInRole           userInRole           = null;
            string subdomain = SessionHelper.GetSession(SessionKey.SubDomain);

            if (!(subdomain == Guid.Empty.ToString())) // thuoc it nhat 1 subdomain
            {
                UserInSubDomainCollection userInSubDomainCollection = new UserInSubDomainCollection();
                UserInSubDomain           userInSubDomain           = new UserInSubDomain();
                userInSubDomain.UserId      = user.Id;
                userInSubDomain.SubDomainId = new Guid(subdomain);
                userInSubDomainCollection.AddDB(userInSubDomain);
                // administrators
                if (args.IsAdministrator)
                {
                    Role roleAdministrator = RoleCollection.GetRoleCollection()
                                             .Single(r => r.Name == System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);
                    userInRole        = new UserInRole();
                    userInRole.RoleId = roleAdministrator.Id;
                    userInRole.UserId = user.Id;
                    userInRoleCollection.AddDB(userInRole);
                }
            }
            else // subdomain : all
            {
                // administrators
                if (args.IsAdministrator)
                {
                    Role roleAdministrator = RoleCollection.GetRoleCollection().Single(r => r.Name == System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"]);
                    userInRole        = new UserInRole();
                    userInRole.RoleId = roleAdministrator.Id;
                    userInRole.UserId = user.Id;
                    userInRoleCollection.AddDB(userInRole);
                }
            }
            DataStatic["DisplayUserList"] = null;
        }
Exemple #2
0
        public static void UserUpdate()
        {
            UserArgs args = PSCDialog.DataShare as PSCPortal.Security.UserArgs;
            CustomMembershipProvider customMembership = new CustomMembershipProvider();
            bool validate = customMembership.ValidateEmail(args.User);

            if (validate == false)
            {
                return;
            }
            args.User.Update();
            string               groupAdmin           = System.Configuration.ConfigurationManager.AppSettings["GroupAdmin"];
            RoleCollection       rolesOfUser          = RoleCollection.GetRoleCollection(args.User.Name);
            Role                 roleAdmin            = rolesOfUser.SingleOrDefault(r => r.Name == groupAdmin);
            UserInRoleCollection userInRoleCollection = new UserInRoleCollection();
            UserInRole           userInRole           = null;

            if (args.IsAdministrator)
            {
                // if user exist role administrator
                if (roleAdmin == null)
                {
                    userInRole = new UserInRole();
                    Role radmin = RoleCollection.GetRoleCollection().Single(r => r.Name == groupAdmin);
                    userInRole.RoleId = radmin.Id;
                    userInRole.UserId = args.User.Id;
                    userInRoleCollection.AddDB(userInRole);
                }
            }
            else
            {
                if (roleAdmin != null)
                {
                    userInRole        = new UserInRole();
                    userInRole.RoleId = roleAdmin.Id;
                    userInRole.UserId = args.User.Id;
                    userInRoleCollection.Add(userInRole);
                    userInRoleCollection.RemoveDB(userInRole);
                }
            }
            DataStatic["DisplayUserList"] = null;
            DataStatic["UserList"]        = null;
        }