예제 #1
0
        private void CreateUserCommand(List <string> args, Common.CmdIO.TTY io, UUID limitedToScene)
        {
            if (args[0] == "help" || args.Count != 4)
            {
                io.Write("create user <firstname> <lastname>");
            }
            else if (limitedToScene != UUID.Zero)
            {
                io.Write("create user not allowed on limited console");
            }
            else if (!IsNameValid(args[1]) || !IsNameValid(args[2]))
            {
                io.Write("name can only contains letters or digits");
            }
            else if (m_UserAccountService.ContainsKey(args[1], args[2]))
            {
                io.Write("user already created");
            }
            else
            {
                var account = new UserAccount
                {
                    IsLocalToGrid = true
                };
                account.Principal.ID        = UUID.Random;
                account.Principal.FirstName = args[2];
                account.Principal.LastName  = args[3];
                account.UserLevel           = 0;

                var authInfo = new UserAuthInfo
                {
                    ID       = account.Principal.ID,
                    Password = io.GetPass("Password")
                };
                try
                {
                    m_UserAccountService.Add(account);
                }
                catch
                {
                    io.WriteFormatted("Could not add user account");
                }

                try
                {
                    m_AuthInfoService.Store(authInfo);
                }
                catch
                {
                    m_UserAccountService.Remove(account.Principal.ID);
                    io.WriteFormatted("Could not add user account");
                }
            }
        }
예제 #2
0
        private void HandleUserAccountCreate(HttpRequest req, Map jsondata)
        {
            var account = new UserAccount();

            account.Principal.ID = UUID.Random;
            string firstname;
            string lastname;
            string password;

            if (!jsondata.TryGetValue("firstname", out firstname) ||
                !jsondata.TryGetValue("lastname", out lastname) ||
                !jsondata.TryGetValue("password", out password))
            {
                m_WebIF.ErrorResponse(req, AdminWebIfErrorResult.InvalidRequest);
                return;
            }
            account.Principal.FirstName = firstname;
            account.Principal.LastName  = lastname;
            int    ival;
            string sval;
            uint   uval;

            if (jsondata.TryGetValue("userlevel", out ival))
            {
                account.UserLevel = ival;
                if (account.UserLevel > 255)
                {
                    m_WebIF.ErrorResponse(req, AdminWebIfErrorResult.InvalidParameter);
                    return;
                }
            }
            if (jsondata.TryGetValue("usertitle", out sval))
            {
                account.UserTitle = sval;
            }
            if (jsondata.TryGetValue("userflags", out uval))
            {
                account.UserFlags = (UserFlags)uval;
            }
            if (jsondata.TryGetValue("email", out sval))
            {
                account.Email = sval;
            }
            try
            {
                m_UserAccountService.Add(account);
            }
            catch
            {
                m_WebIF.ErrorResponse(req, AdminWebIfErrorResult.AlreadyExists);
                return;
            }
            var uai = new UserAuthInfo
            {
                ID       = account.Principal.ID,
                Password = password
            };

            try
            {
                m_AuthInfoService.Store(uai);
            }
            catch
            {
                m_UserAccountService.Remove(account.Principal.ID);
                m_WebIF.ErrorResponse(req, AdminWebIfErrorResult.NotPossible);
                return;
            }
            var res = new Map
            {
                { "id", account.Principal.ID },
                { "firstname", account.Principal.FirstName },
                { "lastname", account.Principal.LastName }
            };
            var resdata = new Map
            {
                ["account"] = res
            };

            m_WebIF.SuccessResponse(req, resdata);
        }