public async Task <bool> GetLoginValidityAsync() { Settings.Settings legacySettings = Settings.Settings.Instance; DsrProfile dsr = await new LoginController().GetByDsrPhoneNumberAsync(legacySettings.DsrPhone); return(this.LoginValid( dsr.LastOnlineLogin, DateTime.Now, legacySettings.ExpirePeriodInDays)); }
protected async Task LoginOffline() { // grab the user from local resource Dsr = await LoginController.GetByDsrPhoneNumberAsync(Settings.DsrPhone); // no local profile present if (Dsr == null) { ShowLoginResultMessage(Resource.String.no_offline_profile); this._canLoginOffline = false; return; } // profile exists, continue // check whether it has been too long since the user logged in online if (!LoginService.LoginValid(Dsr.LastOnlineLogin, DateTime.Today, Settings.ExpirePeriodInDays)) { ShowLoginResultMessage(string.Format(GetString(Resource.String.logging_in_too_long), Settings.ExpirePeriodInDays)); this._canLoginOffline = false; return; } // check the amount of times logged in offline if (Dsr.OfflineLoginAttempts >= Settings.OfflineLoginAttempts) { ShowLoginResultMessage(string.Format(GetString(Resource.String.logging_in_offline_expire), Dsr.OfflineLoginAttempts)); this._canLoginOffline = false; return; } // we're still ok, check the hash IHashing hashing = Resolver.Instance.Get <IHashing>(); string hash = hashing.HashPassword(Settings.DsrPhone, EnteredPin); if (hash != Dsr.PinHash) { Dsr.OfflineLoginAttempts++; await LoginController.SaveAsync(Dsr); ShowLoginResultMessage(Resource.String.wrong_pin); return; } // seem to be right PIN, so continue Dsr.LastOfflineLogin = DateTime.Now; Dsr.OfflineLoginAttempts = 0; await LoginController.SaveAsync(Dsr); ContinueToWelcome(); }
private async Task ProceedWithLogin(LoginResponse loginResponse) { // check if local profile exists this.Dsr = await this.LoginController.GetDsr(loginResponse.Id); // create new profile if (this.Dsr == null) { this.Dsr = new DsrProfile { DsrPhone = Settings.Instance.DsrPhone, FirstName = loginResponse.FirstName, LastName = loginResponse.LastName, LastOfflineLogin = loginResponse.LastOfflineLogin, LastOnlineLogin = loginResponse.LastOnlineLogin, OfflineLoginAttempts = loginResponse.OfflineLoginAttempts, PinHash = loginResponse.PinHash, Id = loginResponse.Id }; } else { // update existing profile this.Dsr.DsrPhone = Settings.Instance.DsrPhone; this.Dsr.FirstName = loginResponse.FirstName; this.Dsr.LastName = loginResponse.LastName; this.Dsr.PinHash = loginResponse.PinHash; this.Dsr.Id = loginResponse.Id; } // when dsr is present we have valid user this.CreateUserSession(); this.Dsr.LastOnlineLogin = DateTime.Now; this.Dsr.LastOfflineLogin = DateTime.Now; this.Dsr.OfflineLoginAttempts = 0; await this.LoginController.SaveAsync(this.Dsr); // fetch and update settings via OTA var serverTimestamp = Settings.Instance.ServerTimeStamp; string carrier = this.OperatorName; var requestParams = string.Format("?carrier={0}&servertimestamp={1}", carrier, serverTimestamp); await this.RemoteOtaService.FetchOtaSettingsAsync(requestParams); // continue to new screen this.ContinueToWelcome(); }