Exemplo n.º 1
0
        public void Dont_Change_Pass_If_Data_Invalid_3()
        {
            // Arrange
            Mock <IAuthProvider> mock = new Mock <IAuthProvider>();

            mock.Setup(m => m.IsValidUser(It.IsAny <string>(), It.Is <char[]>(s => new string(s) == "correct")))
            .Returns(true);
            AdminController        target = new AdminController(mock.Object);
            SettingsIndexViewModel model  = new SettingsIndexViewModel
            {
                CurrentPassword    = "******",
                NewPassword        = "******",
                ConfirmNewPassword = "******"
            };

            // Act
            if (!Helpers.IsValidModel <SettingsIndexViewModel>(model))
            {
                target.ModelState.AddModelError("", "");
            }
            ViewResult result = (ViewResult)target.SettingsPost(model);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 2
0
        public ActionResult Settings(string returnUrl)
        {
            // Получаем текущие настройки для установки контролов в панели управления
            BlogSettings           settings = BlogSettings.ShallowCopy;
            SettingsIndexViewModel model    = new SettingsIndexViewModel
            {
                Settings = settings
            };

            return(View(model));
        }
Exemplo n.º 3
0
        public IActionResult Index([Bind("Succes", "Error")] PlexAuthenticationResultViewModel authResult)
        {
            var vm = new SettingsIndexViewModel(ServerName)
            {
                Apps = _appRepo.ListAll()
            };

            if (!authResult.Succes && authResult.Error == null) // default values, so index was called without parameters
            {
                vm.PlexServerSettingsViewModel = CreatePlexServerSettingsViewModel(null);
                return(View(vm));
            }
            else
            {
                vm.PlexServerSettingsViewModel = CreatePlexServerSettingsViewModel(authResult);
                return(View(vm));
            }
        }
Exemplo n.º 4
0
        public IActionResult Index(ulong guildId, [FromServices] IBot bot,
                                   [FromServices] IDiscordSettings discordSettings, [FromServices] IList <IModule> modules)
        {
            if (bot.IsBotInGuild(guildId))
            {
                var viewModel = new SettingsIndexViewModel
                {
                    GuildId   = guildId,
                    GuildName = bot.GetGuilds().FirstOrDefault(g => g.Id == guildId)?.Name,
                    Modules   = modules.Where(mod => mod.Configurable).ToList()
                };

                return(View(viewModel));
            }

            // Bot is not in guild so redirect to the add bot URL.
            var redirectUrl = Uri.EscapeDataString($"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}");

            return(Redirect(
                       $"https://discordapp.com/api/oauth2/authorize?client_id={discordSettings.ClientId}&permissions=8&redirect_uri={redirectUrl}&scope=bot&guild_id={guildId}"));
        }
Exemplo n.º 5
0
        public ActionResult SettingsPost(SettingsIndexViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!string.IsNullOrEmpty(model.NewPassword) && string.IsNullOrEmpty(model.CurrentPassword))
                {
                    ModelState.AddModelError("CurrentPassword", "Для смены пароля нужно указать текущий пароль");
                }
                else if (string.IsNullOrEmpty(model.NewPassword) && !string.IsNullOrEmpty(model.CurrentPassword))
                {
                    ModelState.AddModelError("NewPassword", "Вы не указали новый пароль");
                }
            }

            string newPassHash = null; // если производится корректная смена пароля, то ниже получит значение

            if (ModelState.IsValid && !string.IsNullOrEmpty(model.NewPassword))
            {
                // Берем логин с сервера, потому что на клиенте он мог измениться
                if (authProvider.IsValidUser(BlogSettings.Current.AdminLogin, model.CurrentPassword.ToCharArray()))
                {
                    // Получаем хэш пароля
                    newPassHash = Convert.ToBase64String(
                        HashPassword.HashPass(model.NewPassword.ToCharArray(), new byte[0]));
                }
                else
                {
                    ModelState.AddModelError("CurrentPassword", "Указанный пароль не соответствует текущему");
                }
            }

            if (ModelState.IsValid)
            {
                // Сохранение новых настроек
                BlogSettings.Current.ChangeSettings(model.Settings, newPassHash, false);
                BlogEngineTK.WebUI.MvcApplication.ClearAppCache();
            }

            return(View(model));
        }
Exemplo n.º 6
0
        public void Change_Pass_If_Data_Valid()
        {
            // Arrange
            Mock <IAuthProvider> mock = new Mock <IAuthProvider>();

            mock.Setup(m => m.IsValidUser(It.IsAny <string>(), It.Is <char[]>(s => new string(s) == "correct")))
            .Returns(true);
            AdminController        target = new AdminController(mock.Object);
            SettingsIndexViewModel model  = new SettingsIndexViewModel
            {
                Settings           = BlogSettings.Current,
                CurrentPassword    = "******",
                NewPassword        = "******",
                ConfirmNewPassword = "******"
            };

            // Act
            ViewResult result = (ViewResult)target.SettingsPost(model);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.ViewData.ModelState.IsValid);
        }
Exemplo n.º 7
0
        public ActionResult Index()
        {
            var model = new SettingsIndexViewModel();

            return(View(model));
        }
Exemplo n.º 8
0
        public ActionResult Index()
        {
            var model = new SettingsIndexViewModel();

            return View(model);
        }