예제 #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);
        }
예제 #2
0
파일: User.cs 프로젝트: KerwinMa/Umbraco
        /// <summary>
        /// Updates the name, login name and password for the user with the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="name">The name.</param>
        /// <param name="lname">The lname.</param>
        /// <param name="email">The email.</param>
        /// <param name="ut">The ut.</param>
        public static void Update(int id, string name, string lname, string email, UserType ut)
        {
            if (!ensureUniqueLoginName(lname, User.GetUser(id)))
            {
                throw new Exception(String.Format("A user with the login '{0}' already exists", lname));
            }


            SqlHelper.ExecuteNonQuery(@"Update umbracoUser set userName=@name, userLogin=@lname, userEmail=@email, UserType=@type where id = @id",
                                      SqlHelper.CreateParameter("@name", name),
                                      SqlHelper.CreateParameter("@lname", lname),
                                      SqlHelper.CreateParameter("@email", email),
                                      SqlHelper.CreateParameter("@type", ut.Id),
                                      SqlHelper.CreateParameter("@id", id));
        }
예제 #3
0
파일: User.cs 프로젝트: KerwinMa/Umbraco
        /// <summary>
        /// Gets all users
        /// </summary>
        /// <returns></returns>
        public static User[] getAll()
        {
            IRecordsReader dr;

            dr = SqlHelper.ExecuteReader("Select id from umbracoUser");

            List <User> users = new List <User>();

            while (dr.Read())
            {
                users.Add(User.GetUser(dr.GetInt("id")));
            }
            dr.Close();

            return(users.OrderBy(x => x.Name).ToArray());
        }