Пример #1
0
        public async Task LoginTest()
        {
            LoginApis loginApis = new LoginApis
                                  (
                LanguagesEnum.EN
                , CountryCodes.KE
                , sqlDB
                                  );
            LoginResponse loginResponse = await loginApis.Login("0721553229", "1234", true);

            List <Permission> existingPermissions = await PermissionsController.Instance.GetAllAsync();

            var downloadedPermissions = loginResponse.Permissions.Select(p => new { p.PermissionId })
                                        .ToList();
            List <Permission> matchingPermissions = existingPermissions
                                                    .Where
                                                    (
                perm => downloadedPermissions.Contains(new { perm.PermissionId })
                                                    ).ToList();

            Assert.AreEqual(downloadedPermissions.Count, matchingPermissions.Count);
        }
Пример #2
0
        /// <summary>
        /// If <paramref name="withRetry"/> is true, this method will try online login three times and if they all fail, the next time it is called with
        /// <paramref name="withRetry"/> as true, it will automatically try offline login.
        /// If however <paramref name="withRetry"/> is false the method will only try online login once and wont revert to offline if it fails.
        /// </summary>
        /// <param name="withRetry">A boolean indicating whether or not to try 3 times</param>
        /// <returns>An empty task</returns>
        protected async Task LoginOnline(bool withRetry = false)
        {
            this.HideLoginResultMessage();

            // change the login text and disable the button
            this.DisableLoginButton();

            var           loginApis = new LoginApis();
            LoginResponse loginResponse;

            if (withRetry)
            {
                // the previous 3 online login tries failed, so we automatically switch to online
                if (this._onlineLoginFailed && this._canLoginOffline)
                {
                    this.LoginOffline();
                    this.EnableLoginButton();
                    return;
                }

                loginResponse = await loginApis.Login(Settings.Instance.DsrPhone, this.EnteredPin, ErrorFilterFlags.DisableErrorHandling);
            }
            else
            {
                loginResponse = await loginApis.Login(Settings.Instance.DsrPhone, this.EnteredPin, true, ErrorFilterFlags.DisableErrorHandling);
            }

            bool loginSuccess = false;

            switch (loginResponse.Code)
            {
            case LoginResponseCode.HttpError:
            case LoginResponseCode.Unknown:
                if (withRetry && this._canLoginOffline)
                {
                    this.ShowLoginResultMessage(Resource.String.online_login_failed);
                    this._onlineLoginFailed = true;
                }
                else
                {
                    this.ShowLoginResultMessage(Resource.String.something_wrong_try_again_login);
                }
                break;

            case LoginResponseCode.Unauthorized:
                this.ShowLoginResultMessage(Resource.String.wrong_pin);
                break;

            case LoginResponseCode.WrongParameters:
                this.ShowLoginResultMessage(Resource.String.something_wrong_try_again);
                break;

            case LoginResponseCode.Success:
                loginSuccess = true;
                break;
            }

            // grab profile from response, we're still good
            if (loginSuccess)
            {
                ISharedPrefService sharedPreferences = Resolver.Instance.Get <ISharedPrefService>();
                sharedPreferences.Save(LoginService.IsFirstLogin, false);

                // check whether the app is up to date
                switch (loginResponse.AppCompatibility)
                {
                case AppCompatibility.UpdateAvailable:
                    this.ShowDialog(this.GetString(Resource.String.update_preferred), this.GetString(Resource.String.update), this.GetString(Resource.String.not_now),
                                    (sender, args) =>
                    {
                        this.GoToPlayStore();
                    },
                                    (sender, args) =>
                    {
                        Task.Run(async() =>
                        {
                            try
                            {
                                await this.ProceedWithLogin(loginResponse);
                            }
                            catch (Exception exception)
                            {
                                Logger.Debug(exception);
                                throw;
                            }
                        });
                    });
                    break;

                case AppCompatibility.UpdateRequired:
                    this.ShowDialog(this.GetString(Resource.String.update_required), this.GetString(Resource.String.update),
                                    (sender, args) =>
                    {
                        this.GoToPlayStore();
                    });
                    break;

                case AppCompatibility.UpToDate:
                    await this.ProceedWithLogin(loginResponse);

                    break;

                case AppCompatibility.Unknown:
                    await this.ProceedWithLogin(loginResponse);

                    break;
                }
            }

            this.EnableLoginButton();
        }