Example #1
0
        public UserManagementModule(ISettingsService <PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService <PlexSettings> plex, IRepository <UserLogins> userLogins, IPlexUserRepository plexRepo
                                    , ISecurityExtensions security, IRequestService req, IAnalytics ana) : base("usermanagement", pr, security)
        {
#if !DEBUG
            Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
#endif
            UserMapper          = m;
            PlexApi             = plexApi;
            PlexSettings        = plex;
            UserLoginsRepo      = userLogins;
            PlexUsersRepository = plexRepo;
            PlexRequestSettings = pr;
            RequestService      = req;
            Analytics           = ana;

            Get["/"] = x => Load();

            Get["/users", true] = async(x, ct) => await LoadUsers();

            Post["/createuser", true] = async(x, ct) => await CreateUser();

            Get["/local/{id}"]      = x => LocalDetails((Guid)x.id);
            Get["/plex/{id}", true] = async(x, ct) => await PlexDetails(x.id);

            Get["/permissions"]       = x => GetEnum <Permissions>();
            Get["/features"]          = x => GetEnum <Features>();
            Post["/updateuser", true] = async(x, ct) => await UpdateUser();

            Post["/deleteuser"] = x => DeleteUser();
        }
        public UserWizardModule(ISettingsService <PlexRequestSettings> pr, ISettingsService <PlexSettings> plex, IPlexApi plexApi,
                                ISettingsService <AuthenticationSettings> auth, ICustomUserMapper m, IAnalytics a) : base("wizard", pr)
        {
            PlexSettings        = plex;
            PlexApi             = plexApi;
            PlexRequestSettings = pr;
            Auth      = auth;
            Mapper    = m;
            Analytics = a;

            Get["/", true] = async(x, ct) =>
            {
                a.TrackEventAsync(Category.Wizard, Action.Start, "Started the wizard", Username, CookieHelper.GetAnalyticClientId(Cookies));

                var settings = await PlexRequestSettings.GetSettingsAsync();

                if (settings.Wizard)
                {
                    return(Context.GetRedirect("~/search"));
                }
                return(View["Index"]);
            };
            Post["/plexAuth"]   = x => PlexAuth();
            Post["/plex", true] = async(x, ct) => await Plex();

            Post["/plexrequest", true] = async(x, ct) => await PlexRequest();

            Post["/auth", true] = async(x, ct) => await Authentication();

            Post["/createuser", true] = async(x, ct) => await CreateUser();
        }
        public UserManagementModule(ISettingsService <PlexRequestSettings> pr, ICustomUserMapper m) : base("usermanagement", pr)
        {
            this.RequiresClaims(UserClaims.Admin);
            Get["/"] = x => Load();

            Get["/users"] = x => LoadUsers();
            UserMapper    = m;
        }
Example #4
0
        public ApiUserModule(ISettingsService <PlexRequestSettings> pr, ICustomUserMapper m, ISecurityExtensions security) : base("api", pr, security)
        {
            Put["PutCredentials", "/credentials/{username}"] = x => ChangePassword(x);

            Get["GetApiKey", "/apikey"] = x => GetApiKey();

            SettingsService = pr;
            UserMapper      = m;
        }
        public UserManagementModule(ISettingsService<PlexRequestSettings> pr, ICustomUserMapper m, IPlexApi plexApi, ISettingsService<PlexSettings> plex) : base("usermanagement", pr)
        {
#if !DEBUG
            this.RequiresClaims(UserClaims.Admin);
#endif
            UserMapper = m;
            PlexApi = plexApi;
            PlexSettings = plex;

            Get["/"] = x => Load();

            Get["/users", true] = async (x, ct) => await LoadUsers();
            Post["/createuser"] = x => CreateUser();
            Get["/local/{id}"] = x => LocalDetails((Guid)x.id);
            Get["/plex/{id}", true] = async (x, ct) => await PlexDetails(x.id);
            Get["/claims"] = x => GetClaims();
        }
Example #6
0
        public LoginModule(ISettingsService <PlexRequestSettings> pr, ICustomUserMapper m) : base(pr)
        {
            UserMapper    = m;
            Get["/login"] = _ =>
            {
                {
                    dynamic model = new ExpandoObject();
                    model.Redirect = Request.Query.redirect.Value ?? string.Empty;
                    model.Errored  = Request.Query.error.HasValue;
                    var adminCreated = UserMapper.DoUsersExist();
                    model.AdminExists = adminCreated;
                    return(View["Index", model]);
                }
            };

            Get["/logout"] = x => this.LogoutAndRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/" : "~/");

            Post["/login"] = x =>
            {
                var username = (string)Request.Form.Username;
                var password = (string)Request.Form.Password;
                var dtOffset = (int)Request.Form.DateTimeOffset;
                var redirect = (string)Request.Form.Redirect;

                var userId = UserMapper.ValidateUser(username, password);

                if (userId == null)
                {
                    return(Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/login?error=true&username="******"~/login?error=true&username="******"userlogin"))
                {
                    redirect = !string.IsNullOrEmpty(BaseUrl) ? $"/{BaseUrl}/search" : "/search";
                }
                return(this.LoginAndRedirect(userId.Value, expiry, redirect));
            };

            Get["/register"] = x =>
            {
                {
                    dynamic model = new ExpandoObject();
                    model.Errored = Request.Query.error.HasValue;

                    return(View["Register", model]);
                }
            };

            Post["/register"] = x =>
            {
                var username = (string)Request.Form.Username;
                var exists   = UserMapper.DoUsersExist();
                if (exists)
                {
                    return(Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/register?error=true" : "~/register?error=true"));
                }
                var userId = UserMapper.CreateAdmin(username, Request.Form.Password);
                Session[SessionKeys.UsernameKey] = username;
                return(this.LoginAndRedirect((Guid)userId));
            };

            Get["/changepassword"]  = _ => ChangePassword();
            Post["/changepassword"] = _ => ChangePasswordPost();
        }
Example #7
0
        public LoginModule(ISettingsService <PlexRequestSettings> pr, ICustomUserMapper m, IResourceLinker linker, IRepository <UserLogins> userLoginRepo, ISecurityExtensions security)
            : base(pr, security)
        {
            UserMapper = m;
            Get["LocalLogin", "/login"] = _ =>
            {
                if (LoggedIn)
                {
                    var url = linker.BuildRelativeUri(Context, "SearchIndex");
                    return(Response.AsRedirect(url.ToString()));
                }
                dynamic model = new ExpandoObject();
                model.Redirect = Request.Query.redirect.Value ?? string.Empty;
                model.Errored  = Request.Query.error.HasValue;
                var adminCreated = UserMapper.DoUsersExist();
                model.AdminExists = adminCreated;
                return(View["Index", model]);
            };

            Get["/logout"] = x =>
            {
                if (Session[SessionKeys.UsernameKey] != null)
                {
                    Session.Delete(SessionKeys.UsernameKey);
                }
                return(CustomModuleExtensions.LogoutAndRedirect(this, !string.IsNullOrEmpty(BaseUrl) ? $"~/{BaseUrl}/" : "~/"));
            };

            Post["/login"] = x =>
            {
                var username = (string)Request.Form.Username;
                var password = (string)Request.Form.Password;
                var dtOffset = (int)Request.Form.DateTimeOffset;
                var redirect = (string)Request.Form.Redirect;

                var userId = UserMapper.ValidateUser(username, password);

                if (userId == null)
                {
                    return
                        (Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl)
                            ? $"~/{BaseUrl}/login?error=true&username="******"~/login?error=true&username="******"userlogin"))
                {
                    redirect = !string.IsNullOrEmpty(BaseUrl) ? $"/{BaseUrl}/search" : "/search";
                }

                userLoginRepo.Insert(new UserLogins
                {
                    LastLoggedIn = DateTime.UtcNow,
                    Type         = UserType.LocalUser,
                    UserId       = userId.ToString()
                });

                return(CustomModuleExtensions.LoginAndRedirect(this, userId.Value, expiry, redirect));
            };

            Get["/register"] = x =>
            {
                {
                    dynamic model = new ExpandoObject();
                    model.Errored = Request.Query.error.HasValue;

                    return(View["Register", model]);
                }
            };

            Post["/register"] = x =>
            {
                var username = (string)Request.Form.Username;
                var exists   = UserMapper.DoUsersExist();
                if (exists)
                {
                    return
                        (Context.GetRedirect(!string.IsNullOrEmpty(BaseUrl)
                            ? $"~/{BaseUrl}/register?error=true"
                            : "~/register?error=true"));
                }
                var userId = UserMapper.CreateUser(username, Request.Form.Password, EnumHelper <Permissions> .All(), 0);
                Session[SessionKeys.UsernameKey] = username;
                return(CustomModuleExtensions.LoginAndRedirect(this, (Guid)userId));
            };

            Get["/changepassword"]  = _ => ChangePassword();
            Post["/changepassword"] = _ => ChangePasswordPost();
        }
Example #8
0
        public UserLoginModule(ISettingsService <AuthenticationSettings> auth, IPlexApi api, ISettingsService <PlexSettings> plexSettings, ISettingsService <PlexRequestSettings> pr,
                               ISettingsService <LandingPageSettings> lp, IAnalytics a, IResourceLinker linker, IRepository <UserLogins> userLogins, IExternalUserRepository <PlexUsers> plexUsers, ICustomUserMapper custom,
                               ISecurityExtensions security, ISettingsService <UserManagementSettings> userManagementSettings, IEmbyApi embyApi, ISettingsService <EmbySettings> emby, IExternalUserRepository <EmbyUsers> embyU,
                               IUserHelper userHelper)
            : base("userlogin", pr, security)
        {
            AuthService         = auth;
            LandingPageSettings = lp;
            Analytics           = a;
            PlexApi             = api;
            PlexSettings        = plexSettings;
            Linker                 = linker;
            UserLogins             = userLogins;
            PlexUserRepository     = plexUsers;
            CustomUserMapper       = custom;
            UserManagementSettings = userManagementSettings;
            EmbySettings           = emby;
            EmbyApi                = embyApi;
            EmbyUserRepository     = embyU;
            UserHelper             = userHelper;

            Post["/", true] = async(x, ct) => await LoginUser();

            Get["/logout"] = x => Logout();

            Get["UserLoginIndex", "/", true] = async(x, ct) =>
            {
                if (Request.Query["landing"] == null)
                {
                    var s = await LandingPageSettings.GetSettingsAsync();

                    if (s.Enabled)
                    {
                        if (s.BeforeLogin) // Before login
                        {
                            if (string.IsNullOrEmpty(Username))
                            {
                                // They are not logged in
                                return
                                    (Context.GetRedirect(Linker.BuildRelativeUri(Context, "LandingPageIndex").ToString()));
                            }
                            return(Context.GetRedirect(Linker.BuildRelativeUri(Context, "SearchIndex").ToString()));
                        }

                        // After login
                        if (string.IsNullOrEmpty(Username))
                        {
                            // Not logged in yet
                            return(Context.GetRedirect(Linker.BuildRelativeUri(Context, "UserLoginIndex").ToString() + "?landing"));
                        }
                        // Send them to landing
                        var landingUrl = Linker.BuildRelativeUri(Context, "LandingPageIndex").ToString();
                        return(Context.GetRedirect(landingUrl));
                    }
                }

                if (!string.IsNullOrEmpty(Username) || IsAdmin)
                {
                    var url = Linker.BuildRelativeUri(Context, "SearchIndex").ToString();
                    return(Response.AsRedirect(url));
                }
                var settings = await AuthService.GetSettingsAsync();

                return(View["Username", settings]);
            };

            Post["/login", true] = async(x, ct) => await UsernameLogin();

            Post["/password", true] = async(x, ct) => await PasswordLogin();
        }