Example #1
0
        static void Main()
        {
            Application.Current.Use(new HtmlFromJsonProvider());
            Application.Current.Use(new PartialToStandaloneHtmlProvider());

            Program.SetupPermissions();

            SystemUsersHandlers.Register();
            SystemUserGroupsHandlers.Register();
            CommitHooks.Register();
            MainHandlers.Register();
            MappingHandlers.Register();
        }
Example #2
0
        public static void Register()
        {
            // Create System User group
            Handle.GET("/UserAdmin/admin/createusergroup", (Request request) =>
            {
                MasterPage master = MainHandlers.GetMasterPageFromSession();
                Json page;

                if (
                    !Helper.TryNavigateTo("/UserAdmin/admin/createusergroup", request,
                                          "/useradmin/viewmodels/RedirectPage.html", out page))
                {
                    master.CurrentPage = page;
                }
                else
                {
                    master.CurrentPage = new CreateUserGroupPage()
                    {
                        Html = "/UserAdmin/viewmodels/partials/administrator/CreateUserGroupPage.html", Uri = request.Uri
                    };
                }

                return(master);
            });

            // Get System user groups
            Handle.GET("/UserAdmin/admin/usergroups", (Request request) =>
            {
                MasterPage master = MainHandlers.GetMasterPageFromSession();
                Json page;

                if (
                    !Helper.TryNavigateTo("/UserAdmin/admin/usergroups", request,
                                          "/useradmin/viewmodels/RedirectPage.html", out page))
                {
                    master.CurrentPage = page;
                }
                else
                {
                    master.CurrentPage = new ListUserGroupsPage()
                    {
                        Html = "/UserAdmin/viewmodels/partials/administrator/ListUserGroupsPage.html", Uri = request.Uri
                    };
                }

                return(master);
            });

            // Get System user group
            Handle.GET("/UserAdmin/admin/usergroups/{?}", (string usergroupid, Request request) =>
            {
                MasterPage master = MainHandlers.GetMasterPageFromSession();
                Json page;

                if (!Helper.TryNavigateTo("/UserAdmin/admin/usergroups/{?}", request, "/useradmin/viewmodels/RedirectPage.html", out page))
                {
                    master.CurrentPage = page;
                    return(master);
                }

                Simplified.Ring3.SystemUserGroup usergroup = Db.SQL <Simplified.Ring3.SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.ObjectID=?", usergroupid).First;

                if (usergroup == null)
                {
                    // TODO: Return a "User Group not found" page
                    return(master);
                    //return (ushort)System.Net.HttpStatusCode.NotFound;
                }

                master.CurrentPage = Db.Scope(() =>
                {
                    var editUserGroupPage = new EditUserGroupPage
                    {
                        Html = "/UserAdmin/viewmodels/partials/administrator/EditUserGroupPage.html",
                        Uri  = request.Uri,
                        Data = usergroup
                    };
                    return(editUserGroupPage);
                });
                return(master);
            });
        }
Example #3
0
        public static void Register()
        {
            string redirectPageHtml = "/useradmin/viewmodels/RedirectPage.html";

            Handle.GET("/useradmin/accessdenied", () =>
            {
                return(new AccessDeniedPage());
            });

            Handle.GET("/useradmin/unauthenticated?return_uri={?}", (string returnUri) =>
            {
                MasterPage master  = MainHandlers.GetMasterPageFromSession();
                master.CurrentPage = Self.GET <UnauthenticatedPage>("/useradmin/partial/unauthenticated?return_uri=" + returnUri);
                return(master);
            });

            Handle.GET("/useradmin/partial/unauthenticated?return_uri={?}", (string returnUri) =>
            {
                return(new UnauthenticatedPage());
            });

            // Create System user
            Handle.GET("/useradmin/admin/createuser", (Request request) =>
            {
                MasterPage master = MainHandlers.GetMasterPageFromSession();

                Json page;
                if (!Helper.TryNavigateTo("/UserAdmin/admin/createuser", request, redirectPageHtml, out page))
                {
                    master.CurrentPage = page;
                }
                else
                {
                    master.CurrentPage = Db.Scope(() =>
                    {
                        var user = new SystemUser();
                        return(new CreateUserPage
                        {
                            Html = "/UserAdmin/viewmodels/partials/administrator/CreateUserPage.html",
                            Uri = request.Uri,
                            Data = user,
                            SystemUserPasswordPage =
                                Self.GET("/useradmin/user/authentication/password/" + user.GetObjectID())
                        });
                    });
                }

                return(master);
            });

            // Get System users
            Handle.GET("/useradmin/admin/users", (Request request) =>
            {
                MasterPage master = MainHandlers.GetMasterPageFromSession();
                Json page;
                if (!Helper.TryNavigateTo("/useradmin/admin/users", request, redirectPageHtml, out page))
                {
                    master.CurrentPage = page;
                }
                else
                {
                    master.CurrentPage = new ListUsersPage()
                    {
                        Html = "/UserAdmin/viewmodels/partials/administrator/ListUsersPage.html", Uri = request.Uri
                    };
                }
                return(master);
            });

            Handle.GET("/UserAdmin/persons/{?}", (string userid) =>
            {
                return(Self.GET("/UserAdmin/admin/users/" + userid));
            });

            Handle.GET("/UserAdmin/admin/users/{?}", (string userid, Request request) =>
            {
                Json page;
                MasterPage master = MainHandlers.GetMasterPageFromSession();

                if (!Helper.TryNavigateTo("/UserAdmin/admin/users/{?}", request, redirectPageHtml, out page))
                {
                    master.CurrentPage = page;
                    return(master);
                }

                // Get system user
                SystemUser user = Db.SQL <SystemUser>("SELECT o FROM Simplified.Ring3.SystemUser o WHERE o.ObjectID = ?", userid).First;

                if (user == null)
                {
                    // TODO: Return a "User not found" page
                    return(master);
                }

                SystemUser systemUser      = Helper.GetCurrentSystemUser();
                SystemUserGroup adminGroup = Db.SQL <SystemUserGroup>("SELECT o FROM Simplified.Ring3.SystemUserGroup o WHERE o.Name = ?", Program.AdminGroupName).First;

                // Check if current user has permission to get this user instance
                if (Helper.IsMemberOfGroup(systemUser, adminGroup))
                {
                    if (user.WhoIs is Person)
                    {
                        master.CurrentPage = Db.Scope(() => new EditPersonPage
                        {
                            Html = "/UserAdmin/viewmodels/partials/administrator/EditPersonPage.html",
                            Uri  = request.Uri,
                            Data = user,
                            SystemUserAuthenticationSettingsPage =
                                Self.GET("/useradmin/user/authentication/settings/" + user.GetObjectID())
                        });

                        return(master);
                    }
                }
                else if (user == systemUser)
                {
                    // User can edit it's self
                }
                else
                {
                    // No rights
                    // User trying to view another's users data

                    // User has no permission, redirect to app's root page
                    master.CurrentPage = new RedirectPage()
                    {
                        Html        = redirectPageHtml,
                        RedirectUrl = "/useradmin"
                    };
                    return(master);
                }

                return(master);
            });

            // User authentication settings
            Handle.GET("/useradmin/user/authentication/settings/{?}", (string userId) => new Json(),
                       new HandlerOptions {
                SelfOnly = true
            });

            // User password settings
            Handle.GET("/useradmin/user/authentication/password/{?}", (string userId) => new Json(),
                       new HandlerOptions {
                SelfOnly = true
            });
        }