Esempio n. 1
0
        /// <summary>
        /// Creates Admin User if missing and adds it to the admin group.
        /// </summary>
        private void CreateAdminSystemUserIfMissing(string adminPassword, out string message, out bool isAlert)
        {
            message = string.Empty;
            isAlert = false;
            SystemUser      user  = GetAdminUser();
            SystemUserGroup group = GetAdminUserGroup();

            if (IsInGroup(user, group))
            {
                message = "There is already an Admin user created";
                isAlert = true;
                return;//Do nothing if there's already an admin user
            }

            // There is no system user belonging to the admin group
            Db.Transact(() =>
            {
                if (group == null)
                {
                    group = new SystemUserGroup
                    {
                        Name        = AdminGroupName,
                        Description = AdminGroupDescription
                    };
                }

                if (user == null)
                {
                    var person = new Person()
                    {
                        FirstName = AdminUsername,
                        LastName  = AdminUsername
                    };

                    user        = SystemUser.RegisterSystemUser(AdminUsername, AdminEmail, adminPassword);
                    user.WhatIs = person;
                }

                // Add the admin group to the system admin user
                var member = new SystemUserGroupMember
                {
                    WhatIs = user,
                    ToWhat = group
                };
            });
            message = $"Admin user with username = '******' was created";
        }
Esempio n. 2
0
        /// <summary>
        /// Assure that there is at least one system user beloning to the admin group
        /// </summary>
        internal static void AssureAdminSystemUser()
        {
            SystemUserGroup group =
                Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?",
                                         AdminGroupName).First;
            SystemUser user =
                Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.Username = ?", AdminUsername)
                .First;

            if (group != null && user != null && SystemUser.IsMemberOfGroup(user, group))
            {
                return;
            }

            // There is no system user beloning to the admin group
            Db.Transact(() =>
            {
                if (group == null)
                {
                    group             = new SystemUserGroup();
                    group.Name        = AdminGroupName;
                    group.Description = AdminGroupDescription;
                }

                if (user == null)
                {
                    Person person = new Person()
                    {
                        FirstName = AdminUsername,
                        LastName  = AdminUsername
                    };

                    user        = SystemUser.RegisterSystemUser(AdminUsername, AdminEmail, AdminPassword);
                    user.WhatIs = person;
                }

                // Add the admin group to the system admin user
                SystemUserGroupMember member = new Simplified.Ring3.SystemUserGroupMember();

                member.WhatIs = user;
                member.ToWhat = group;
            });
        }