Esempio n. 1
0
        private async Task <Negotiator> LoadRequests()
        {
            var settings = await PrSettings.GetSettingsAsync();

            var custom = await CustomizationSettings.GetSettingsAsync();

            return(View["Index", new RequestsIndexViewModel {
                            CustomizationSettings = custom, PlexRequestSettings = settings
                        }]);
        }
Esempio n. 2
0
        private async Task <Response> GetFilterAndSortSettings()
        {
            var s = await CustomizationSettings.GetSettingsAsync();

            var sortVal = EnumHelper <SortOptions> .GetDisplayValue((SortOptions)s.DefaultSort);

            var filterVal = EnumHelper <FilterOptions> .GetDisplayValue((FilterOptions)s.DefaultFilter);

            var vm = new
            {
                DefaultSort   = sortVal,
                DefaultFilter = filterVal
            };

            return(Response.AsJson(vm));
        }
Esempio n. 3
0
        public async Task <OmbiIdentityResult> SubmitResetPassword([FromBody] SubmitPasswordReset email)
        {
            // Check if account exists
            var user = await UserManager.FindByEmailAsync(email.Email);

            var defaultMessage = new OmbiIdentityResult
            {
                Successful = true,
                Errors     = new List <string> {
                    "If this account exists you should recieve a password reset link."
                }
            };

            if (user == null)
            {
                return(defaultMessage);
            }

            // We have the user
            var token = await UserManager.GeneratePasswordResetTokenAsync(user);

            // We now need to email the user with this token
            var emailSettings = await EmailSettings.GetSettingsAsync();

            var customizationSettings = await CustomizationSettings.GetSettingsAsync();

            var appName = (string.IsNullOrEmpty(customizationSettings.ApplicationName)
                ? "Ombi"
                : customizationSettings.ApplicationName);

            customizationSettings.AddToUrl("/token?token=");
            var url = customizationSettings.ApplicationUrl;

            await EmailProvider.SendAdHoc(new NotificationMessage
            {
                To      = user.Email,
                Subject = $"{appName} Password Reset",
                Message = $"You recently made a request to reset your {appName} account. Please click the link below to complete the process.<br/><br/>" +
                          $"<a href=\"{url}{token}\"> Reset </a>"
            }, emailSettings);

            return(defaultMessage);
        }
Esempio n. 4
0
        public async Task <OmbiIdentityResult> SubmitResetPassword([FromBody] SubmitPasswordReset email)
        {
            // Check if account exists
            var user = await UserManager.FindByEmailAsync(email.Email);

            var defaultMessage = new OmbiIdentityResult
            {
                Successful = true,
                Errors     = new List <string> {
                    "If this account exists you should recieve a password reset link."
                }
            };

            if (user == null)
            {
                return(defaultMessage);
            }


            var customizationSettings = await CustomizationSettings.GetSettingsAsync();

            var appName = (string.IsNullOrEmpty(customizationSettings.ApplicationName)
                ? "Ombi"
                : customizationSettings.ApplicationName);

            var emailSettings = await EmailSettings.GetSettingsAsync();

            customizationSettings.AddToUrl("/token?token=");
            var url = customizationSettings.ApplicationUrl;

            if (user.UserType == UserType.PlexUser)
            {
                await EmailProvider.SendAdHoc(new NotificationMessage
                {
                    To      = user.Email,
                    Subject = $"{appName} Password Reset",
                    Message =
                        $"You recently made a request to reset your {appName} account. Please click the link below to complete the process.<br/><br/>" +
                        $"<a href=\"https://www.plex.tv/sign-in/password-reset/\"> Reset </a>"
                }, emailSettings);
            }
            else if (user.UserType == UserType.EmbyUser && user.IsEmbyConnect)
            {
                await EmailProvider.SendAdHoc(new NotificationMessage
                {
                    To      = user.Email,
                    Subject = $"{appName} Password Reset",
                    Message =
                        $"You recently made a request to reset your {appName} account.<br/><br/>" +
                        $"To reset your password you need to go to <a href=\"https://emby.media/community/index.php\">Emby.Media</a> and then click on your Username > Edit Profile > Email and Password"
                }, emailSettings);
            }
            else
            {
                // We have the user
                var token = await UserManager.GeneratePasswordResetTokenAsync(user);

                var encodedToken = WebUtility.UrlEncode(token);

                await EmailProvider.SendAdHoc(new NotificationMessage
                {
                    To      = user.Email,
                    Subject = $"{appName} Password Reset",
                    Message =
                        $"You recently made a request to reset your {appName} account. Please click the link below to complete the process.<br/><br/>" +
                        $"<a href=\"{url}{encodedToken}\"> Reset </a>"
                }, emailSettings);
            }

            return(defaultMessage);
        }
Esempio n. 5
0
        public async Task NotifyAsync(NotificationOptions model, Settings.Settings.Models.Settings settings)
        {
            Settings.ClearCache();
            if (settings == null)
            {
                await NotifyAsync(model);
            }

            var notificationSettings = (T)settings;

            if (!ValidateConfiguration(notificationSettings))
            {
                return;
            }

            // Is this a test?
            // The request id for tests is -1
            // Also issues are 0 since there might not be a request associated
            if (model.RequestId > 0)
            {
                await LoadRequest(model.RequestId, model.RequestType);
            }

            Customization = await CustomizationSettings.GetSettingsAsync();

            try
            {
                switch (model.NotificationType)
                {
                case NotificationType.NewRequest:
                    await NewRequest(model, notificationSettings);

                    break;

                case NotificationType.Issue:
                    await NewIssue(model, notificationSettings);

                    break;

                case NotificationType.RequestAvailable:
                    await AvailableRequest(model, notificationSettings);

                    break;

                case NotificationType.RequestApproved:
                    await RequestApproved(model, notificationSettings);

                    break;

                case NotificationType.Test:
                    await Test(model, notificationSettings);

                    break;

                case NotificationType.RequestDeclined:
                    await RequestDeclined(model, notificationSettings);

                    break;

                case NotificationType.ItemAddedToFaultQueue:
                    await AddedToRequestQueue(model, notificationSettings);

                    break;

                case NotificationType.IssueResolved:
                    await IssueResolved(model, notificationSettings);

                    break;

                case NotificationType.IssueComment:
                    await IssueComment(model, notificationSettings);

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (NotImplementedException)
            {
                // Do nothing, it's not implimented meaning it might not be ready or even used
            }
        }