Esempio n. 1
0
        public override async Task <IDisplayResult> UpdateAsync(GoogleAuthenticationSettings settings, BuildEditorContext context)
        {
            if (context.GroupId == GoogleConstants.Features.GoogleAuthentication)
            {
                var user = _httpContextAccessor.HttpContext?.User;
                if (user == null || !await _authorizationService.AuthorizeAsync(user, Permissions.ManageGoogleAuthentication))
                {
                    return(null);
                }

                var model = new GoogleAuthenticationSettingsViewModel();
                await context.Updater.TryUpdateModelAsync(model, Prefix);

                if (context.Updater.ModelState.IsValid)
                {
                    var protector = _dataProtectionProvider.CreateProtector(GoogleConstants.Features.GoogleAuthentication);

                    settings.ClientID     = model.ClientID;
                    settings.ClientSecret = protector.Protect(model.ClientSecret);
                    settings.CallbackPath = model.CallbackPath;
                    await _shellHost.ReloadShellContextAsync(_shellSettings);
                }
            }
            return(await EditAsync(settings, context));
        }
Esempio n. 2
0
        public bool CheckSettings(GoogleAuthenticationSettings settings)
        {
            var obj = new GoogleAuthenticationSettingsViewModel()
            {
                ClientID     = settings.ClientID,
                CallbackPath = settings.CallbackPath,
                ClientSecret = settings.ClientSecret
            };
            var vc = new ValidationContext(obj);

            return(Validator.TryValidateObject(obj, vc, ImmutableArray.CreateBuilder <ValidationResult>()));
        }