コード例 #1
0
        /// <summary>
        /// Grant a privilege to a user
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="privilege"></param>
        /// <returns></returns>

        public static void GrantPrivilege(
            string userName,
            string privilege)
        {
            if (!PrivilegesMx.IsValidPrivilegeName(privilege))
            {
                throw new Exception("Not a valid privilege");
            }
            UserObjectDao.SetUserParameter(userName, "Privilege" + Lex.CapitalizeFirstLetters(privilege), "True");             // authorize by default
            return;
        }
コード例 #2
0
        /// <summary>
        /// Process command line to create a user
        /// </summary>
        /// <param name="commandLine"></param>
        /// <returns></returns>

        public static string CreateUser(
            string commandLine)
        {
            string tok, msg;

            Lex lex = new Lex();

            lex.OpenString(commandLine);

            if (!Security.IsAdministrator(SS.I.UserName))
            {
                return("You must be a Mobius administrator to create users");
            }

            string userName    = lex.GetUpper();          // get user name
            bool   interactive = Lex.IsNullOrEmpty(userName);

            while (true)
            {
                UserInfo ui = new UserInfo();

                int i1 = userName.IndexOf(@"\");
                if (i1 < 0)
                {
                    i1 = userName.IndexOf(@"/"); // try forward slash
                }
                if (i1 < 0)                      // domain not specified, default is AM
                {
                    ui.UserName = userName;
                }
                else if (i1 > 0)
                {
                    ui.UserDomainName = userName.Substring(0, i1);
                    ui.UserName       = userName.Substring(i1 + 1);
                }

                if (interactive)                 // prompt
                {
                    DialogResult dr = CreateUserDialog.ShowDialog(ui, "Create User");
                    if (dr == DialogResult.Cancel)
                    {
                        return("");
                    }
                }

                else
                {                 // Syntax: CREATE USER [domain\]userid firstname [mi] lastname [emailAddress] [company] [site] [department]
                    ui.FirstName = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                    tok          = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                    if (tok.Length == 1)
                    {
                        ui.MiddleInitial = tok;
                    }
                    else
                    {
                        lex.Backup();
                    }
                    ui.LastName     = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                    ui.EmailAddress = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                    ui.Company      = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                    ui.Site         = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                    ui.Department   = Lex.CapitalizeFirstLetters(Lex.RemoveAllQuotes(lex.Get()));
                }

                UserInfo existingUi = Security.ReadUserInfo(ui.UserName);

                try
                {
                    Security.CreateUser(ui);
                    if (existingUi == null)
                    {
                        msg = "User successfully created";
                    }
                    else
                    {
                        msg = "User information updated";
                    }
                    msg += "\n\n" +
                           "User: "******"\n" +
                           "Domain: " + ui.UserDomainName + "\n" +
                           "First Name: " + ui.FirstName + "\n" +
                           "Middle Initial: " + ui.MiddleInitial + "\n" +
                           "Last Name: " + ui.LastName;
                }
                catch (Exception ex) { msg = "User creation failed: " + ex.Message; }

                if (!interactive)
                {
                    return(msg);
                }

                MessageBoxMx.Show(msg);
                userName = "";
            }
        }