Ejemplo n.º 1
0
        private async Task LoadProfileAsync()
        {
            var state = await AuthenticationState.GetAuthenticationStateAsync();

            if (state.User.Identity.IsAuthenticated)
            {
                using (Loading.Start())
                    Profile = await Queries.QueryAsync(new GetProfile());
            }
        }
Ejemplo n.º 2
0
        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            var state = await AuthenticationState.GetAuthenticationStateAsync();

            var loggedIn = await AuthService.Refresh();

            if (!loggedIn)
            {
                Logger.LogWarning("User not logged in");
                NavigationManager.NavigateTo("/login");
            }
            Logger.LogInformation("Refreshed token");
            await base.OnParametersSetAsync();
        }
Ejemplo n.º 3
0
        protected async Task GetAuthenticatedUser()
        {
            try
            {
                var result = await AuthenticationState.GetAuthenticationStateAsync();

                CurrentUser   = result.User;
                CurrentUserId = result.User.FindFirstValue(ClaimTypes.NameIdentifier);

                if (CurrentUser.Identity.IsAuthenticated)
                {
                    var FirstName = CurrentUser.FindFirstValue("FirstName");
                    var LastName  = CurrentUser.FindFirstValue("LastName");

                    CurrentUsersName = $"{FirstName} {LastName}";
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 4
0
        protected override async Task OnInitializedAsync()
        {
            UserName = AppState.UserName;
            if (string.IsNullOrEmpty(UserName))
            {
                var auth = await AuthenticationState.GetAuthenticationStateAsync();

                UserName = auth?.User?.Identity?.Name;
            }
            //Temp for testing
            //var random = new Random();
            //UserName = $"{userName}{random.Next(1, 999)}";
            hubConnection = new HubConnectionBuilder()
                            .WithUrl($"{FunctionBaseUrl}/", options =>
            {
                options.Headers.Add("x-ms-client-principal-id", UserName);
            })
                            .Build();

            hubConnection.On <object>("getAlert", (message) =>
            {
                var encodedMsg = $"{message}";
                Console.WriteLine($"received message: {encodedMsg}");
                Toaster.Add(message.ToString(), MatToastType.Primary);
                messages.Add(message.ToString());
                StateHasChanged();
            });
            hubConnection.On <object>("alertArena", async(message) =>
            {
                var encodedMsg = $"{message}";
                Console.WriteLine($"received Alert: {encodedMsg}");
                var activeArenas = await PublicClient.GetActiveArenas();
                ArenaService.UpdateArenas(activeArenas);
                StateHasChanged();
            });
            hubConnection.On <object>("leaveArena", (message) =>
            {
                var encodedMsg = $"{message}";
                Console.WriteLine($"received message: {encodedMsg}");
                messages.Add(encodedMsg);
                OnNewMessage.InvokeAsync(encodedMsg);
            });
            hubConnection.On <object>("resultAlert", (message) =>
            {
                Console.WriteLine($"'resultAlert' Triggered message: {message}");
                var result    = ArenaResultMessage.FromJson(message.ToString());
                var arenaName = result.Group;
                ArenaService.ArenaComplete(arenaName);
                Console.WriteLine($"'ArenaComplete' values:name: {arenaName} winner {result.DuelWinner} loser: {result.DuelLoser}");
                Toaster.Add(result.Message, MatToastType.Primary);
                messages.Add(result.Message);
            });
            hubConnection.On <object>("resultActual", (arenaObj) =>
            {
                Console.WriteLine("'resultActual' Triggered");
                var encodedMsg = $"{arenaObj}";
                var arenaAlert = ArenaResultMessage.FromJson(arenaObj.ToString());
                messages.Add($"{arenaAlert.DuelWinner} defeated {arenaAlert.DuelLoser} in arena {arenaAlert.Group}");
                Console.WriteLine($"received group message: {encodedMsg}");
                StateHasChanged();
            });
            hubConnection.On <object>("joinAlert", (message) =>
            {
                var encodedMsg = $"{message}";

                var jObj      = JObject.Parse(message.ToString());
                var arenaName = jObj["group"]?.ToString();
                var userJoin  = jObj["user"]?.ToString();
                var arenaText = jObj["message"]?.ToString();
                Console.WriteLine($"'joinAlert' Triggered: {encodedMsg}");
                ArenaService.JoinArena(arenaName, userJoin);
                Toaster.Add(arenaText, MatToastType.Primary);
                StateHasChanged();
            });
            hubConnection.On <object>("showArena", group =>
            {
                Console.WriteLine($"Create arena message received: {group}");
                var jObj = JObject.Parse(group.ToString());

                var user     = jObj["user"]?.ToString();
                var groupobj = jObj["group"]?.ToString();
                var chalObj  = jObj["challenge"]?.ToString();
                Toaster.Add($"User {user} joined Arena: {groupobj} with Challenge: {chalObj}", MatToastType.Info);
                messages.Add($"User {user} joined Arena: {groupobj} with Challenge: {chalObj}");
                StateHasChanged();
            });

            await hubConnection.StartAsync();

            var arenasInit = await PublicClient.GetActiveArenas();

            ArenaService.UpdateArenas(arenasInit);
        }