Exemple #1
0
        public IndexViewModel(
            ProtectedLocalStorage localStorageService,
            GameService gameService
            )
        {
            _localStorageService = localStorageService;
            _gameService         = gameService;

            Debug.WriteLine($"{nameof(IndexViewModel)} #{m_Index} .ctor");

            string[] filterWords() => Words.Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();

            this.WhenActivated(context => {
                Debug.WriteLine($"{nameof(IndexViewModel)} #{m_Index} Activating");

                // local storage
                this.WhenAnyValue(x => x.Username)
                .Skip(1)     // init
                .Do(x => _localStorageService.SetAsync(nameof(Username), x ?? string.Empty))
                .Subscribe()
                .DisposeWith(context);

                this.WhenAnyValue(x => x.IsLoggedIn)
                .Skip(1)     // init
                .Do(x => _localStorageService.SetAsync(nameof(IsLoggedIn), x))
                .Subscribe()
                .DisposeWith(context);

                Words.ObserveCollectionChanges()
                .Skip(1)     // init
                .Do(x => _localStorageService.SetAsync(nameof(Words), filterWords()))
                .Subscribe()
                .DisposeWith(context);

                this.WhenAnyValue(x => x.Player)
                .Select(x => x != null)
                .BindTo(this, x => x.IsLoggedIn)
                .DisposeWith(context);

                this.WhenAnyValue(x => x.Player)
                .Select(x => x != null ? x.GetConnectionToken() : Disposable.Empty)
                .DisposeMany()
                .Subscribe()
                .DisposeWith(context);

                this.WhenAnyValue(x => x.Player)
                .Where(x => x != null)
                .Select(x =>
                        x.GetWordsInteraction.RegisterHandler(interactionContext =>
                                                              interactionContext.SetOutput(filterWords())
                                                              )
                        )
                .DisposeMany()
                .Subscribe()
                .DisposeWith(context);

                Disposable.Create(() => Debug.WriteLine($"{nameof(IndexViewModel)} #{m_Index} Disposing"))
                .DisposeWith(context);
            });
        }
Exemple #2
0
 public Base64VM(IJSRuntime jsRunTime, ProtectedLocalStorage protectedLocalStorage, ClipboardService clipboard, IWebHostEnvironment hostingEnvironment)
     : base(jsRunTime, protectedLocalStorage, clipboard, hostingEnvironment)
 {
     PageName = "Base64 Functions";
     Url      = "base64";
     TextType = "application/text";
     Functions.Add("Encode", Encode);
     Functions.Add("Decode", Decode);
 }
Exemple #3
0
        public JwtVM(IJSRuntime jsRunTime, ProtectedLocalStorage protectedLocalStorage, ClipboardService clipboard, IWebHostEnvironment hostingEnvironment)
            : base(jsRunTime, protectedLocalStorage, clipboard, hostingEnvironment)
        {
            PageName = "Jwt Functions";
            Url      = "Jwt";
            TextType = "application/ld+json";

            Functions.Add("Decode", Decode);
            Functions.Add("Decode Detailed", DecodeDetailed);
        }
Exemple #4
0
 public Diff2VM(IJSRuntime jsRunTime, ProtectedLocalStorage protectedLocalStorage, ClipboardService clipboard, IWebHostEnvironment hostingEnvironment)
     : base(jsRunTime, protectedLocalStorage, clipboard, hostingEnvironment)
 {
     PageName             = "Diff Text";
     TextType             = "application/ld+json";
     LeftTextBoxTitle     = "Source 1";
     RightTextBoxTitle    = "Source 2";
     RightTextboxReadOnly = false;
     Functions.Add("Format", Format);
 }
Exemple #5
0
 public UrlVM(IJSRuntime jsRunTime, ProtectedLocalStorage protectedLocalStorage, ClipboardService clipboard, IWebHostEnvironment hostingEnvironment)
     : base(jsRunTime, protectedLocalStorage, clipboard, hostingEnvironment)
 {
     PageName = "URL Functions";
     Url      = "url";
     TextType = "application/text";
     Functions.Add("Encode", UrlEncode);
     Functions.Add("Decode", UrlDecode);
     AddCssToCodeMirror("HorizontalScroll");
 }
Exemple #6
0
 public XmlVM(IJSRuntime jsRunTime, ProtectedLocalStorage protectedLocalStorage, ClipboardService clipboard, IWebHostEnvironment hostingEnvironment)
     : base(jsRunTime, protectedLocalStorage, clipboard, hostingEnvironment)
 {
     PageName = "XML Functions";
     Url      = "xml";
     TextType = "application/xml";
     Functions.Add("Format", Format);
     Functions.Add("Validate", Validate);
     Functions.Add("Minify", Minify);
     Functions.Add("To Json", ToJson);
 }
Exemple #7
0
 public TextVM(IJSRuntime jsRunTime, ProtectedLocalStorage protectedLocalStorage, ClipboardService clipboard, IWebHostEnvironment hostingEnvironment)
     : base(jsRunTime, protectedLocalStorage, clipboard, hostingEnvironment)
 {
     PageName = "Text Functions";
     Url      = "text";
     TextType = "application/text";
     Functions.Add("Metrics", TextCalculate);
     Functions.Add("Upper Case", ToUpperCase);
     Functions.Add("Lower Case", ToLowerCase);
     Functions.Add("Capitalize", ToCapitalize);
 }
 public TokenManager(AppSettings appSettings, IHttpClientFactory httpClientFactory, TokenProvider tokenProvider, ProtectedLocalStorage protectedLocalStorage)
 {
     _httpClientFactory = httpClientFactory;
     _options           = new OpenIdConnectOptions
     {
         Authority            = appSettings.OpenIdConnect.Authority,
         ClientId             = appSettings.OpenIdConnect.ClientId,
         ClientSecret         = appSettings.OpenIdConnect.ClientSecret,
         RequireHttpsMetadata = appSettings.OpenIdConnect.RequireHttpsMetadata,
     };
     _tokenProvider         = tokenProvider;
     _protectedLocalStorage = protectedLocalStorage;
 }
Exemple #9
0
        public async Task ValidFormSubmitted(EditContext editContext)
        {
            authorization_result        = null;
            email_validation_message    = null;
            password_validation_message = null;

            LoginModel model = (LoginModel)editContext.Model;

            if (model.email == "" || model.email == null)
            {
                email_validation_message = Localizer.GetText("Required");
            }
            if (model.password == "" || model.password == null)
            {
                password_validation_message = Localizer.GetText("Required");
            }

            if (email_validation_message != null || password_validation_message != null)
            {
                return;
            }


            var security_result = await _security.Authenticate(loginModel.email, loginModel.password);

            if (security_result.Item1)
            {
                await ProtectedSessionStore.SetAsync("GUID", security_result.Item2);

                var Locale = await ProtectedLocalStorage.GetAsync <string>("Culture");

                if (Locale != null && Locale != "Select Culture")
                {
                    LocOptions.Value.SetDefaultCulture(Locale);
                }

                navigationManager.NavigateTo("/main", forceLoad: true);
            }
            else
            {
                authorization_result = Localizer.GetText("WrongPassword");
                loginModel.email     = null;
                loginModel.password  = null;
            }
        }
Exemple #10
0
 public UserPreferences(ProtectedLocalStorage preferenceStore, IPlayerService playerService)
 {
     _preferenceStore = preferenceStore ?? throw new ArgumentNullException(nameof(preferenceStore));
     _playerService   = playerService ?? throw new ArgumentNullException(nameof(playerService));
 }
Exemple #11
0
 public ApiAuthenticationStateProvider(HttpClientService httpClientService, ProtectedLocalStorage localStorage, IHttpContextAccessor accessor)
 {
     _httpClientService = httpClientService;
     _storage           = localStorage;
     _accessor          = accessor;
 }
Exemple #12
0
 public CenterService(HttpClient httpClient, ProtectedLocalStorage protectedLocalStorage)
 {
     this.httpClient            = httpClient;
     this.protectedLocalStorage = protectedLocalStorage;
 }
Exemple #13
0
 public AppState(ProtectedLocalStorage localStorage)
 {
     _storage = localStorage;
 }
Exemple #14
0
 public JWTAuthenticationProvider(IHttpClientFactory httpClientFactory, ProtectedLocalStorage protectedLocalStorage)
 {
     this.httpClientFactory = httpClientFactory;
     this.LocalStorage      = protectedLocalStorage;
 }