Ejemplo n.º 1
0
        public bool Save()
        {
            string[] nameAndMail = Alias.Split("|".ToCharArray());
            string name = nameAndMail[0];
            string email = nameAndMail.Length > 0 ? nameAndMail[1] : "";
            string password = nameAndMail.Length > 1 ? nameAndMail[2] : "";
            string loginName = nameAndMail.Length > 2 ? nameAndMail[3] : "";
            if (cms.businesslogic.member.Member.InUmbracoMemberMode() && TypeID != -1)
            {
                cms.businesslogic.member.MemberType dt = new cms.businesslogic.member.MemberType(TypeID);
                cms.businesslogic.member.Member m = cms.businesslogic.member.Member.MakeNew(name, loginName, email, dt, BusinessLogic.User.GetUser(_userID));
                m.Password = password;                
                m.LoginName = loginName.Replace(" ", "").ToLower();

                NewMemberUIEventArgs e = new NewMemberUIEventArgs();
                this.OnNewMember(e, password, m);

                _returnUrl = "members/editMember.aspx?id=" + m.Id.ToString();
            }
            else
            {
                MembershipCreateStatus mc = new MembershipCreateStatus();
                Membership.CreateUser(name, password, email, "empty", "empty", true, out mc);
                if (mc != MembershipCreateStatus.Success)
                {
                    throw new Exception("Error creating Member: " + mc.ToString());
                }
                _returnUrl = "members/editMember.aspx?id=" + System.Web.HttpContext.Current.Server.UrlEncode(name);
            }

            return true;
        }
Ejemplo n.º 2
0
        public bool Save()
        {
            string[] nameAndMail = Alias.Split("|".ToCharArray());
            string   name        = nameAndMail[0];
            string   email       = nameAndMail.Length > 0 ? nameAndMail[1] : "";
            string   password    = nameAndMail.Length > 1 ? nameAndMail[2] : "";
            string   loginName   = nameAndMail.Length > 2 ? nameAndMail[3] : "";

            if (cms.businesslogic.member.Member.InUmbracoMemberMode() && TypeID != -1)
            {
                cms.businesslogic.member.MemberType dt = new cms.businesslogic.member.MemberType(TypeID);
                cms.businesslogic.member.Member     m  = cms.businesslogic.member.Member.MakeNew(name, loginName, email, dt, BusinessLogic.User.GetUser(_userID));
                m.Password  = password;
                m.LoginName = loginName.Replace(" ", "").ToLower();

                NewMemberUIEventArgs e = new NewMemberUIEventArgs();
                this.OnNewMember(e, password, m);

                _returnUrl = "members/editMember.aspx?id=" + m.Id.ToString();
            }
            else
            {
                MembershipCreateStatus mc = new MembershipCreateStatus();
                Membership.CreateUser(name, password, email, "empty", "empty", true, out mc);
                if (mc != MembershipCreateStatus.Success)
                {
                    throw new Exception("Error creating Member: " + mc.ToString());
                }
                _returnUrl = "members/editMember.aspx?id=" + System.Web.HttpContext.Current.Server.UrlEncode(name);
            }

            return(true);
        }
Ejemplo n.º 3
0
 private void AddMemberTypeProperty(ref MemberType m)
 {
     var ddt = DataTypeDefinition.GetAll().First();
     //needs to start with a letter
     var alias = "m" + Guid.NewGuid().ToString("N");
     m.AddPropertyType(ddt, alias, alias);
     //make sure it's there
     var prop = m.getPropertyType(alias);
     Assert.IsInstanceOfType(prop, typeof(PropertyType));
 }
Ejemplo n.º 4
0
		/// <summary>
		/// Create a new MemberType
		/// </summary>
		/// <param name="Text">The name of the MemberType</param>
		/// <param name="u">Creator of the MemberType</param>
		public static MemberType MakeNew(User u,string Text) 
		{		
			int ParentId= -1;
			int level = 1;
			Guid uniqueId = Guid.NewGuid();
			CMSNode n = CMSNode.MakeNew(ParentId, _objectType, u.Id, level,Text, uniqueId);

			ContentType.Create(n.Id, Text,"");
	        MemberType mt = new MemberType(n.Id);
		    mt.IconUrl = "member.gif";
            NewEventArgs e = new NewEventArgs();
            mt.OnNew(e);

            return mt; 
		}
Ejemplo n.º 5
0
        public int create(memberCarrier carrier, int memberTypeId, string username, string password)
        {
            Authenticate(username, password);

            // Some validation
            if (carrier == null)
            {
                throw new Exception("No carrier specified");
            }
            if (carrier.Id != 0)
            {
                throw new Exception("ID cannot be specifed when creating. Must be 0");
            }
            if (string.IsNullOrEmpty(carrier.DisplayedName))
            {
                carrier.DisplayedName = "unnamed";
            }

            // we fetch the membertype
            umbraco.cms.businesslogic.member.MemberType mtype = new umbraco.cms.businesslogic.member.MemberType(memberTypeId);

            // Check if the membertype exists
            if (mtype == null)
            {
                throw new Exception("Membertype " + memberTypeId + " not found");
            }

            // Get the user that creates
            umbraco.BusinessLogic.User user = GetUser(username, password);

            // Create the new member
            umbraco.cms.businesslogic.member.Member newMember = umbraco.cms.businesslogic.member.Member.MakeNew(carrier.DisplayedName, mtype, user);

            // We iterate the properties in the carrier
            if (carrier.MemberProperties != null)
            {
                foreach (memberProperty updatedproperty in carrier.MemberProperties)
                {
                    umbraco.cms.businesslogic.property.Property property = newMember.getProperty(updatedproperty.Key);
                    if (property != null)
                    {
                        property.Value = updatedproperty.PropertyValue;
                    }
                }
            }
            return(newMember.Id);
        }
        public IEnumerable<PickerItem> GetAllMemberTypesWithAlias()
        {
            var list = new List<PickerItem>();

            Guid[] guids = umbraco.cms.businesslogic.CMSNode.getAllUniquesFromObjectType(new Guid("9b5416fb-e72f-45a9-a07b-5a9a2709ce43"));
            foreach (var g in guids)
            {

                var mt = new MemberType(g);
                var p = new PickerItem
                {
                    Id = mt.Alias,
                    Value = mt.Text
                };
                list.Add(p);

            }
            return list;
        }
Ejemplo n.º 7
0
        public override bool PerformSave()
        {
            var nameAndMail = Alias.Split("|".ToCharArray());
            var name = nameAndMail[0];
            var email = nameAndMail.Length > 0 ? nameAndMail[1] : "";
            var password = nameAndMail.Length > 1 ? nameAndMail[2] : "";
            var loginName = nameAndMail.Length > 2 ? nameAndMail[3] : "";
            if (Member.InUmbracoMemberMode() && TypeID != -1)
            {
                var dt = new MemberType(TypeID);                
                var provider = (providers.members.UmbracoMembershipProvider) Membership.Provider;
                MembershipCreateStatus status;
                //TODO: We are not supporting q/a - passing in empty here
                var created = provider.CreateUser(dt.Alias, 
                    loginName.Replace(" ", "").ToLower(), //dunno why we're doing this but that's how it has been so i'll leave it i guess
                    password, email, "", "", true, Guid.NewGuid(), out status);

                var member = Member.GetMemberFromLoginName(created.UserName);

                var e = new NewMemberUIEventArgs();
                this.OnNewMember(e, password, member);

                _returnUrl = "members/editMember.aspx?id=" + member.Id.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                var mc = new MembershipCreateStatus();
                Membership.CreateUser(name, password, email, "empty", "empty", true, out mc);
                if (mc != MembershipCreateStatus.Success)
                {
                    throw new Exception("Error creating Member: " + mc);
                }
                _returnUrl = "members/editMember.aspx?id=" + HttpUtility.UrlEncode(name);
            }

            return true;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Deletes all members of the membertype specified
 /// 
 /// Used when a membertype is deleted
 /// 
 /// Use with care
 /// </summary>
 /// <param name="dt">The membertype which are being deleted</param>
 public static void DeleteFromType(MemberType dt)
 {
     var objs = getContentOfContentType(dt);
     foreach (Content c in objs)
     {
         // due to recursive structure document might already been deleted..
         if (IsNode(c.UniqueId))
         {
             Member tmp = new Member(c.UniqueId);
             tmp.delete();
         }
     }
 }
Ejemplo n.º 9
0
        public static Member MakeNew(string Name, string LoginName, string Email, MemberType mbt, User u)
        {
            var loginName = (!String.IsNullOrEmpty(LoginName)) ? LoginName : Name;

            if (String.IsNullOrEmpty(loginName))
                throw new ArgumentException("The loginname must be different from an empty string", "loginName");

            // Test for e-mail
            if (Email != "" && Member.GetMemberFromEmail(Email) != null)
                throw new Exception(String.Format("Duplicate Email! A member with the e-mail {0} already exists", Email));
            else if (Member.GetMemberFromLoginName(loginName) != null)
                throw new Exception(String.Format("Duplicate User name! A member with the user name {0} already exists", loginName));

            Guid newId = Guid.NewGuid();

            //create the cms node first
            CMSNode newNode = MakeNew(-1, _objectType, u.Id, 1, Name, newId);

            //we need to create an empty member and set the underlying text property
            Member tmp = new Member(newId, true);
            tmp.SetText(Name);

            //create the content data for the new member
            tmp.CreateContent(mbt);

            // Create member specific data ..
            SqlHelper.ExecuteNonQuery(
                "insert into cmsMember (nodeId,Email,LoginName,Password) values (@id,@email,@loginName,'')",
                SqlHelper.CreateParameter("@id", tmp.Id),
                SqlHelper.CreateParameter("@loginName", loginName),
                SqlHelper.CreateParameter("@email", Email));

            //read the whole object from the db
            Member m = new Member(newId);

            NewEventArgs e = new NewEventArgs();

            m.OnNew(e);

            m.Save();

            return m;
        }
Ejemplo n.º 10
0
 public static Member MakeNew(string Name, string Email, MemberType mbt, User u)
 {
     return MakeNew(Name, "", Email, mbt, u);
 }
        public int create(memberCarrier carrier, int memberTypeId, string username, string password)
        {
            Authenticate(username, password);

            // Some validation
            if (carrier == null) throw new Exception("No carrier specified");
            if (carrier.Id != 0) throw new Exception("ID cannot be specifed when creating. Must be 0");
            if (string.IsNullOrEmpty(carrier.DisplayedName)) carrier.DisplayedName = "unnamed";

            // we fetch the membertype
            umbraco.cms.businesslogic.member.MemberType mtype = new umbraco.cms.businesslogic.member.MemberType(memberTypeId);

            // Check if the membertype exists
            if (mtype == null) throw new Exception("Membertype " + memberTypeId + " not found");

            // Get the user that creates
            umbraco.BusinessLogic.User user = GetUser(username, password);

            // Create the new member
            umbraco.cms.businesslogic.member.Member newMember = umbraco.cms.businesslogic.member.Member.MakeNew(carrier.DisplayedName, mtype, user);

            // We iterate the properties in the carrier
            if (carrier.MemberProperties != null)
            {
                foreach (memberProperty updatedproperty in carrier.MemberProperties)
                {
                    umbraco.cms.businesslogic.property.Property property = newMember.getProperty(updatedproperty.Key);
                    if (property != null)
                    {
                        property.Value = updatedproperty.PropertyValue;
                    }
                }
            }
            return newMember.Id;
        }
Ejemplo n.º 12
0
 private static ContentType.TabI GetTabByCaption(MemberType mt, string caption)
 {
     return mt.getVirtualTabs.FirstOrDefault(t => t.Caption == caption);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Returns an XPathNodeIterator of the specified member-type.
        /// </summary>
        /// <param name="memberTypeId">The member type id.</param>
        /// <param name="includeTabs">if set to <c>true</c> [include tabs].</param>
        /// <param name="includePropertyTypes">if set to <c>true</c> [include property types].</param>
        /// <returns>A node-set of the specified member-type.</returns>
        public static XPathNodeIterator GetMemberType(int memberTypeId, bool includeTabs, bool includePropertyTypes)
        {
            try
            {
                var xd = new XmlDocument();
                var memberType = new MemberType(memberTypeId);

                if (memberType != null)
                {
                    AppendMemberType(xd, memberType, includeTabs, includePropertyTypes);
                }

                return xd.CreateNavigator().Select("/MemberType");
            }
            catch (Exception ex)
            {
                return ex.ToXPathNodeIterator();
            }
        }
        public void MyTestInitialize()
        {
            //need to create a member type for the provider
            m_MemberType = MemberType.MakeNew(User.GetUser(0), Guid.NewGuid().ToString("N"));

            m_Provider = new UmbracoMembershipProvider(); // TODO: Initialize to an appropriate value

            //initialize the provider
            var config = new NameValueCollection();
            config.Add("enablePasswordRetrieval", "false");
            config.Add("enablePasswordReset", "false");
            config.Add("requiresQuestionAndAnswer", "false");
            config.Add("defaultMemberTypeAlias", m_MemberType.Alias);
            config.Add("passwordFormat", "Hashed");

            m_Provider.Initialize(string.Empty, config);
        }
 void UpdateTabs(XDocument xmlDoc, MemberType docType)
 {
     var tabs = docType.getVirtualTabs;
     var updatedTabs = xmlDoc.Descendants("Tabs").Descendants("Tab").Select(x => x.Element("Caption").Value);
     var currentNames = tabs.Select(x => x.Caption);
     var toDelete = tabs.Where(x => !updatedTabs.Contains(x.Caption));
     var toAdd = updatedTabs.Where(x => !currentNames.Contains(x));
     foreach (var t in toDelete)
         docType.DeleteVirtualTab(t.Id);
     foreach (var t in toAdd)
         docType.AddVirtualTab(t);
 }
        void UpdateProperties(XDocument xmlDoc, MemberType docType)
        {
            var updatedProperties = xmlDoc.Descendants("GenericProperty");
            var updatedPropertiesNames = updatedProperties.Select(x => x.Element("Alias").Value);

            var props = PropertyType.GetAll().Where(x => x.ContentTypeId == docType.Id);

            var matchingProps = props.Where(x => updatedPropertiesNames.Contains(x.Alias));

            var toDelete = props.Where(x => !matchingProps.Contains(x));
            var newProperties = updatedProperties.Where(x => !matchingProps.Select(y => y.Alias).Contains(x.Element("Alias").Value));

            foreach (var p in toDelete)
                p.delete();
            var allDtd = DataTypeDefinition.GetAll();
            var tabs = docType.getVirtualTabs;
            foreach (var p in matchingProps)
            {
                var match = updatedProperties.Where(x => x.Element("Alias").Value == p.Alias).Single();
                var dtd = allDtd.Where(x => x.UniqueId == new Guid(match.Element("Definition").Value)).Single();

                p.DataTypeDefinition = dtd;
                p.Description = match.Element("Description").Value;
                var t = tabs.Where(x => x.Caption == match.Element("Tab").Value).FirstOrDefault();
                if (t != null)
                    p.TabId = t.Id;
                p.Mandatory = bool.Parse(match.Element("Mandatory").Value);
                p.ValidationRegExp = match.Element("Validation").Value;
                p.Name = match.Element("Name").Value;
                p.Save();
            }

            foreach (var m in newProperties)
            {
                var dtd = allDtd.Where(x => x.UniqueId == new Guid(m.Element("Definition").Value)).Single();
                var p = PropertyType.MakeNew(dtd, docType, m.Element("Name").Value, m.Element("Alias").Value);

                p.Description = m.Element("Description").Value;

                var t = tabs.Where(x => x.Caption == m.Element("Tab").Value).FirstOrDefault();
                if (t != null)
                    p.TabId = t.Id;

                p.Mandatory = bool.Parse(m.Element("Mandatory").Value);
                p.ValidationRegExp = m.Element("Validation").Value;
                p.Save();
            }

            if (newProperties.Any())
            {
                var newProps = PropertyType.GetAll().Where(x => x.ContentTypeId == docType.Id);

                foreach (var u in Member.GetAllAsList().Where(x => x.ContentType.Id == docType.Id))
                {
                    var added = false;
                    foreach (var p in newProps)
                    {
                        var prop = u.getProperty(p);
                        if (prop == null)
                        {
                            prop = u.addProperty(p, u.Version);
                            prop.Value = "";
                            added = true;
                        }
                    }
                    if (added)
                    {
                        u.Save();
                    }
                }
            }
        }