Exemplo n.º 1
0
        /// <summary>
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="memberTypeAlias"></param>
        /// <param name="username">The user name for the new user.</param>
        /// <param name="password">The password for the new user.</param>
        /// <param name="email">The e-mail address for the new user.</param>
        /// <param name="passwordQuestion">The password question for the new user.</param>
        /// <param name="passwordAnswer">The password answer for the new user</param>
        /// <param name="isApproved">Whether or not the new user is approved to be validated.</param>
        /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
        /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"></see> enumeration value indicating whether the user was created successfully.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the information for the newly created user.
        /// </returns>
        public MembershipUser CreateUser(string memberTypeAlias, string username, string password, string email, string passwordQuestion,
                                         string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            if (Member.GetMemberFromLoginName(username) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }
            else if (Member.GetMemberFromEmail(email) != null && RequiresUniqueEmail)
            {
                status = MembershipCreateStatus.DuplicateEmail;
            }
            else
            {
                var memberType = MemberType.GetByAlias(memberTypeAlias);
                if (memberType == null)
                {
                    throw new InvalidOperationException("Could not find a member type with alias " + memberTypeAlias + ". Ensure your membership provider configuration is up to date and that the default member type exists.");
                }

                Member m = Member.MakeNew(username, email, memberType, User.GetUser(0));
                m.Password = password;

                MembershipUser mUser =
                    ConvertToMembershipUser(m);

                // custom fields
                if (!String.IsNullOrEmpty(m_PasswordRetrievalQuestionPropertyTypeAlias))
                {
                    UpdateMemberProperty(m, m_PasswordRetrievalQuestionPropertyTypeAlias, passwordQuestion);
                }

                if (!String.IsNullOrEmpty(m_PasswordRetrievalAnswerPropertyTypeAlias))
                {
                    UpdateMemberProperty(m, m_PasswordRetrievalAnswerPropertyTypeAlias, passwordAnswer);
                }

                if (!String.IsNullOrEmpty(m_ApprovedPropertyTypeAlias))
                {
                    UpdateMemberProperty(m, m_ApprovedPropertyTypeAlias, isApproved);
                }

                if (!String.IsNullOrEmpty(m_LastLoginPropertyTypeAlias))
                {
                    mUser.LastActivityDate = DateTime.Now;
                    UpdateMemberProperty(m, m_LastLoginPropertyTypeAlias, mUser.LastActivityDate);
                }

                // save
                m.Save();

                status = MembershipCreateStatus.Success;

                return(mUser);
            }
            return(null);
        }
Exemplo n.º 2
0
        private IContentTypeBase SyncMemberType(ContentTypeRegistration registration, IContentTypeBase result)
        {
            result.ResetDirtyProperties(false);
            Save(result); //need to save to ensure no sync issues when we load from the legacy API
            bool modified = false;
            var  member   = new umbraco.cms.businesslogic.member.MemberType(result.Id);

            foreach (var prop in member.PropertyTypes)
            {
                var propReg = registration.Properties.SingleOrDefault(x => x.Alias == prop.Alias);
                if (propReg != null)
                {
                    var attr = propReg.Metadata.GetCodeFirstAttribute <MemberPropertyAttribute>();
                    if (attr != null)
                    {
                        if (attr.MemberCanEdit != member.MemberCanEdit(prop))
                        {
                            member.setMemberCanEdit(prop, attr.MemberCanEdit);
                            modified = true;
                        }
                        if (attr.ShowOnProfile != member.ViewOnProfile(prop))
                        {
                            member.setMemberViewOnProfile(prop, attr.ShowOnProfile);
                            modified = true;
                        }
                    }
                }
            }

            if (modified)
            {
                modified = false;
                member.Save();
            }

            return(_service.Get(member.Id));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="memberTypeAlias"></param>
        /// <param name="username">The user name for the new user.</param>
        /// <param name="password">The password for the new user.</param>
        /// <param name="email">The e-mail address for the new user.</param>
        /// <param name="passwordQuestion">The password question for the new user.</param>
        /// <param name="passwordAnswer">The password answer for the new user</param>
        /// <param name="isApproved">Whether or not the new user is approved to be validated.</param>
        /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
        /// <param name="status">A <see cref="T:System.Web.Security.MembershipCreateStatus"></see> enumeration value indicating whether the user was created successfully.</param>
        /// <returns>
        /// A <see cref="T:System.Web.Security.MembershipUser"></see> object populated with the information for the newly created user.
        /// </returns>
        protected override MembershipUser PerformCreateUser(string memberTypeAlias, string username, string password, string email, string passwordQuestion,
                                                            string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            if (Member.GetMemberFromLoginName(username) != null)
            {
                status = MembershipCreateStatus.DuplicateUserName;
                LogHelper.Warn <UmbracoMembershipProvider>("Cannot create member as username already exists: " + username);
                return(null);
            }

            if (Member.GetMemberFromEmail(email) != null && RequiresUniqueEmail)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                LogHelper.Warn <UmbracoMembershipProvider>(
                    "Cannot create member as a member with the same email address exists: " + email);
                return(null);
            }

            var memberType = MemberType.GetByAlias(memberTypeAlias);

            if (memberType == null)
            {
                throw new InvalidOperationException("Could not find a member type with alias " + memberTypeAlias + ". Ensure your membership provider configuration is up to date and that the default member type exists.");
            }

            var m = Member.MakeNew(username, email, memberType, User.GetUser(0));

            string salt;
            var    encodedPassword = EncryptOrHashNewPassword(password, out salt);

            //set the password on the member
            m.ChangePassword(FormatPasswordForStorage(encodedPassword, salt));

            // custom fields
            if (string.IsNullOrEmpty(PasswordRetrievalQuestionPropertyTypeAlias) == false)
            {
                UpdateMemberProperty(m, PasswordRetrievalQuestionPropertyTypeAlias, passwordQuestion);
            }

            if (string.IsNullOrEmpty(PasswordRetrievalAnswerPropertyTypeAlias) == false)
            {
                UpdateMemberProperty(m, PasswordRetrievalAnswerPropertyTypeAlias, passwordAnswer);
            }

            if (string.IsNullOrEmpty(ApprovedPropertyTypeAlias) == false)
            {
                UpdateMemberProperty(m, ApprovedPropertyTypeAlias, isApproved ? 1 : 0);
            }

            if (string.IsNullOrEmpty(LastLoginPropertyTypeAlias) == false)
            {
                UpdateMemberProperty(m, LastLoginPropertyTypeAlias, DateTime.Now);
            }

            if (string.IsNullOrEmpty(LastPasswordChangedPropertyTypeAlias) == false)
            {
                UpdateMemberProperty(m, LastPasswordChangedPropertyTypeAlias, DateTime.Now);
            }

            var mUser = ConvertToMembershipUser(m);

            // save
            m.Save();

            status = MembershipCreateStatus.Success;

            return(mUser);
        }