コード例 #1
0
ファイル: User.cs プロジェクト: lulzzz/ifolder
        Create(
            string Userguid,
            string Username,
            string Password,
            string Firstname,
            string Lastname,
            string Fullname,
            string Distinguished)
        {
            Member           member = null;
            RegistrationInfo info   = new RegistrationInfo();

            if (domain == null)
            {
                log.Debug("Domain instance == null");
            }

            try
            {
                member = domain.GetMemberByName(Username);
                if (member == null)
                {
                    string guid = (Userguid != null && Userguid != "")
                                                        ? Userguid : Guid.NewGuid().ToString();

                    member =
                        new Member(
                            Username,
                            guid,
                            Access.Rights.ReadOnly,
                            Firstname,
                            Lastname);

                    // Simias server stores a simple MD5 hash of the password
                    Property pwd = new Property(InternalUser.pwdProperty, HashPassword(Password));
                    pwd.LocalProperty = true;
                    member.Properties.ModifyProperty(pwd);

                    member.FN = (Fullname != null) ? Fullname : Firstname + " " + Lastname;

                    Property dnProp =
                        (Distinguished != null && Distinguished != "")
                                                                ? new Property("DN", Distinguished)
                                                                : new Property("DN", Username);
                    member.Properties.ModifyProperty(dnProp);
                    domain.SetType(member as Node, InternalUser.userType);
                    domain.SetType(member as Node, InternalUser.memberMarker);
                    domain.Commit(member);

                    info.Status   = RegistrationStatus.UserCreated;
                    info.Message  = "Successful";
                    info.UserGuid = guid;
                }
                else
                {
                    info.Status  = RegistrationStatus.UserAlreadyExists;
                    info.Message = "Specified user already exists!";
                }
            }
            catch (Exception e1)
            {
                log.Error(e1.Message);
                log.Error(e1.StackTrace);
                info.Status  = RegistrationStatus.InternalException;
                info.Message = e1.Message;
            }

            return(info);
        }
コード例 #2
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);
        }