示例#1
0
文件: User.cs 项目: lulzzz/ifolder
        /// <summary>
        /// Method to retrieve the capabilities of a user identity
        /// provider.
        /// </summary>
        /// <returns>providers capabilities</returns>
        public UserProviderCaps GetCapabilities()
        {
            UserProviderCaps caps = null;

            if (User.provider != null)
            {
                caps = User.provider.GetCapabilities();
            }

            return(caps);
        }
示例#2
0
文件: User.cs 项目: lulzzz/ifolder
        /// <summary>
        /// Method to retrieve the capabilities of a user identity
        /// provider.
        /// </summary>
        /// <returns>providers capabilities</returns>
        public UserProviderCaps GetCapabilities()
        {
            UserProviderCaps caps = new UserProviderCaps();

            caps.CanCreate    = true;
            caps.CanDelete    = true;
            caps.CanModify    = true;
            caps.ExternalSync = false;

            return(caps);
        }
示例#3
0
文件: User.cs 项目: lulzzz/ifolder
        /// <summary>
        /// Method to create a user/identity in the external user database.
        /// Some external systems may not allow for creation of new users.
        /// </summary>
        /// <param name="Password" mandatory="true">Password associated to the user.</param>
        /// <returns>RegistrationStatus</returns>
        public RegistrationInfo Create(string Password)
        {
            RegistrationInfo info;

            if (User.provider != null)
            {
                if (Password != null)
                {
                    UserProviderCaps caps = User.provider.GetCapabilities();
                    if (caps.CanCreate == true)
                    {
                        // Verify the user doesn't already exist
                        Domain domain = store.GetDomain(store.DefaultDomain);
                        if (domain.GetMemberByName(this.username) == null)
                        {
                            // Call the user provider to create the user
                            log.Debug("Creating member: {0}", this.username);

                            // guarantee a full name exists
                            if (this.fullname == null)
                            {
                                this.fullname = this.username;
                            }

                            info = User.provider.Create(
                                this.userguid,
                                this.username,
                                Password,
                                this.firstname,
                                this.lastname,
                                this.fullname,
                                this.dn);

                            // Some providers may create the user in the server
                            // domain - so verify a few things
                            if (info.Status == RegistrationStatus.UserCreated)
                            {
                                bool   commit = false;
                                Member member = domain.GetMemberByName(this.username);
                                if (member == null)
                                {
                                    string guid;
                                    if (info.UserGuid != null && info.UserGuid != "")
                                    {
                                        // Guid from the provider?
                                        guid = info.UserGuid;
                                    }
                                    else
                                    if (this.userguid != null)
                                    {
                                        // Guid from the caller?
                                        guid = this.userguid;
                                    }
                                    else
                                    {
                                        guid = Guid.NewGuid().ToString();
                                    }

                                    member =
                                        new Member(
                                            this.username,
                                            guid,
                                            Access.Rights.ReadOnly,
                                            this.firstname,
                                            this.lastname);

                                    if (this.fullname != null)
                                    {
                                        member.FN = this.fullname;
                                    }
                                    else
                                    if (this.firstname != null && this.lastname != null)
                                    {
                                        member.FN = this.firstname + " " + this.lastname;
                                    }

                                    Property dnProp = new Property("DN", info.DistinguishedName);
                                    member.Properties.ModifyProperty(dnProp);
                                    commit = true;
                                }
                                else
                                {
                                    // FIXME
                                    // verify non-mandatory properties
                                }

                                if (this.email != null && this.email != "")
                                {
                                    Property emailProp = new Property("Email", this.email);
                                    member.Properties.ModifyProperty(emailProp);
                                    commit = true;
                                }

                                if (commit == true)
                                {
                                    domain.Commit(member);
                                }
                            }
                        }
                        else
                        {
                            info         = new RegistrationInfo(RegistrationStatus.UserAlreadyExists);
                            info.Message = "Member already exists";
                        }
                    }
                    else
                    {
                        info         = new RegistrationInfo(RegistrationStatus.MethodNotSupported);
                        info.Message = "Provider can't create users";
                    }
                }
                else
                {
                    info         = new RegistrationInfo(RegistrationStatus.PasswordPolicyException);
                    info.Message = "Password can't be null";
                }
            }
            else
            {
                info         = new RegistrationInfo(RegistrationStatus.NoRegisteredUserProvider);
                info.Message = User.noProviderMessage;
            }

            return(info);
        }