Пример #1
0
        public static async Task <bool> UserLogoutAsync(IPageDialogService dialogService,
                                                        LoginService loginService, SystemStatusService systemStatusService,
                                                        AppStatus appStatus)
        {
            await systemStatusService.ReadFromFileAsync();

            await loginService.ReadFromFileAsync();

            loginService.SingleItem = new LoginResponseDto();
            await loginService.WriteToFileAsync();

            systemStatusService.SingleItem.UserID                 = loginService.SingleItem.Id;
            systemStatusService.SingleItem.Account                = loginService.SingleItem.Account;
            systemStatusService.SingleItem.IsLogin                = false;
            systemStatusService.SingleItem.LoginedTime            = DateTime.Now;
            systemStatusService.SingleItem.Token                  = loginService.SingleItem.Token;
            systemStatusService.SingleItem.RefreshToken           = loginService.SingleItem.RefreshToken;
            systemStatusService.SingleItem.TokenExpireMinutes     = loginService.SingleItem.TokenExpireMinutes;
            systemStatusService.SingleItem.RefreshTokenExpireDays = loginService.SingleItem.RefreshTokenExpireDays;
            systemStatusService.SingleItem.SetExpireDatetime();

            //await systemStatusService.WriteToFileAsync();
            await AppStatusHelper.WriteAndUpdateAppStatus(systemStatusService, appStatus);

            return(true);
        }
Пример #2
0
        public static async Task <bool> UserLoginAsync(IPageDialogService dialogService,
                                                       LoginService loginService, SystemStatusService systemStatusService, LoginRequestDto loginRequestDTO,
                                                       AppStatus appStatus)
        {
            var fooResult = await loginService.PostAsync(loginRequestDTO);

            if (fooResult.Status != true)
            {
                await dialogService.DisplayAlertAsync("發生錯誤", fooResult.Message, "確定");

                return(false);
            }

            systemStatusService.SingleItem.UserID                 = loginService.SingleItem.Id;
            systemStatusService.SingleItem.Account                = loginService.SingleItem.Account;
            systemStatusService.SingleItem.IsLogin                = true;
            systemStatusService.SingleItem.LoginedTime            = DateTime.Now;
            systemStatusService.SingleItem.Token                  = loginService.SingleItem.Token;
            systemStatusService.SingleItem.RefreshToken           = loginService.SingleItem.RefreshToken;
            systemStatusService.SingleItem.TokenExpireMinutes     = loginService.SingleItem.TokenExpireMinutes;
            systemStatusService.SingleItem.RefreshTokenExpireDays = loginService.SingleItem.RefreshTokenExpireDays;
            systemStatusService.SingleItem.SetExpireDatetime();

            //await systemStatusService.WriteToFileAsync();
            await AppStatusHelper.WriteAndUpdateAppStatus(systemStatusService, appStatus);

            return(true);
        }
Пример #3
0
        public static async Task <bool> CheckAndRefreshToken(IPageDialogService dialogService,
                                                             RefreshTokenService refreshTokenService, SystemStatusService systemStatusService,
                                                             AppStatus appStatus)
        {
            if (appStatus.SystemStatus.TokenExpireDatetime > DateTime.Now)
            {
                #region Token 尚在有效期限
                return(true);

                #endregion
            }
            else
            {
                #region Token 已經失效了,需要更新
                var fooResult = await refreshTokenService.GetAsync();

                if (fooResult.Status != true)
                {
                    await dialogService.DisplayAlertAsync("發生錯誤", fooResult.Message, "確定");

                    return(false);
                }
                systemStatusService.SingleItem                        = appStatus.SystemStatus;
                systemStatusService.SingleItem.IsLogin                = true;
                systemStatusService.SingleItem.LoginedTime            = DateTime.Now;
                systemStatusService.SingleItem.Token                  = refreshTokenService.SingleItem.Token;
                systemStatusService.SingleItem.RefreshToken           = refreshTokenService.SingleItem.RefreshToken;
                systemStatusService.SingleItem.TokenExpireMinutes     = refreshTokenService.SingleItem.TokenExpireMinutes;
                systemStatusService.SingleItem.RefreshTokenExpireDays = refreshTokenService.SingleItem.RefreshTokenExpireDays;
                systemStatusService.SingleItem.SetExpireDatetime();
                #endregion
            }

            //await systemStatusService.WriteToFileAsync();
            await AppStatusHelper.WriteAndUpdateAppStatus(systemStatusService, appStatus);

            return(true);
        }