Exemplo n.º 1
0
        protected override async Task OnInitializedAsync()
        {
            base.OnInitialized();
            await Task.Delay(2000);

            var loggedinUser = (await AuthenticationStateTask).User;

            if (loggedinUser.IsInRole("Admin"))
            {
                Console.WriteLine($"User {loggedinUser.Identity.Name} is in role admin");
            }
            //var user = await LocalStorage.GetItemAsync<UserDto>(MagicStrings.Local_UserDetails);
            var token = await LocalStorage.GetItemAsync <string>(MagicStrings.Local_Token);

            var id   = JwtParser.ParseIdFromJwt(token);
            var user = await AuthenticationApiService.GetUserAsync(id);

            AuthenticatedUser = new UserDetailsDto();
            MiniMapper.CopyProperties(AuthenticatedUser, user);
            AuthenticatedUser.Role = JwtParser.ParseRolesFromJwt(token).FirstOrDefault();
            FormUser = new UserDetailsDto();
            MiniMapper.CopyProperties(FormUser, AuthenticatedUser);
            EditContext = new EditContext(FormUser);
            EditContext.OnFieldChanged += EditContext_OnFieldChanged;
        }
Exemplo n.º 2
0
        private async Task LoginUser()
        {
            ShowAuthenticationErrors = false;
            IsProcessing             = true;
            var result = await AuthenticationApiService.Login(UserForAuthentication);

            if (result.IsSuccessful)
            {
                IsProcessing = false;

                var absoluteUri = new Uri(NavigationManager.Uri);
                var queryParam  = HttpUtility.ParseQueryString(absoluteUri.Query);
                ReturnUrl = queryParam["returnUrl"];
                if (string.IsNullOrEmpty(ReturnUrl))
                {
                    NavigationManager.NavigateTo("/", forceLoad: true);
                }
                else
                {
                    NavigationManager.NavigateTo("/" + ReturnUrl, forceLoad: true);
                }
            }
            else
            {
                IsProcessing             = false;
                Errors                   = result.ErrorMessage;
                ShowAuthenticationErrors = true;
            }
        }
Exemplo n.º 3
0
        protected async override Task OnInitializedAsync()
        {
            var result = await AuthenticationApiService.Logout();

            if (!result.IsSuccessful)
            {
                UtilityServices.ShowNotification(NotificationSeverity.Error, "Logout failed", result.Errors.ToArray());
            }

            NavigationManager.NavigateTo("/");
        }
Exemplo n.º 4
0
        async Task Save()
        {
            //! Id == null ==> Post sonst put
            var result = await AuthenticationApiService.EditUserAsync(FormUser);

            if (result.IsSuccessful)
            {
                NavigationManager.NavigateTo("/", false);
            }
            else
            {
                UtilityServices.ShowNotification(NotificationSeverity.Error, "Save Userdata failed", result.Errors.ToArray());
            }
        }
Exemplo n.º 5
0
        protected async override Task OnInitializedAsync()
        {
            //await Task.Delay(2000);
            await base.OnInitializedAsync();

            ApplicationUsers = new List <UserDetailsDto>();
            var users = await AuthenticationApiService.GetUsersWithRolesAsync();

            if (users == null)
            {
                NavigationManager.NavigateTo("/logout");
            }
            ApplicationUsers = users.ToList();
        }
Exemplo n.º 6
0
        async Task DeleteConfirmation(UserDetailsDto user)
        {
            bool ok = (await DialogService.Confirm("Are you sure to delete user?", "Delete User", new ConfirmOptions()
            {
                OkButtonText = "Yes", CancelButtonText = "No"
            })).GetValueOrDefault();

            if (ok)
            {
                var result = await AuthenticationApiService.DeleteUserAsync(user.Id);

                if (result.IsSuccessful)
                {
                    ApplicationUsers.Remove(user);
                    await UsersGrid.Reload();
                }
                else
                {
                    UtilityServices.ShowNotification(NotificationSeverity.Error, "Delete User failed", result.Errors.ToArray());
                    NavigationManager.NavigateTo("/users", true);
                }
            }
        }
Exemplo n.º 7
0
        private async Task <string> GetAccessToken(UserCredentials credentials)
        {
            var token = await AuthenticationApiService.Login(credentials.Login, credentials.Password);

            return(token.AccessToken);
        }