/// <summary> /// Verifies email, if <paramref name="verificationCode"/> is correct. /// </summary> /// <param name="verificationCode"></param> /// <returns></returns> public async Task <IdentityResult> VerifyPhoneNumberAsync(string verificationCode) { CheckLoginStatus(); var user = await _userRepository.GetFirstOrDefaultAsync(a => a.UserName == _userName).ConfigureAwait(false); user.ThrowIfParameterIsNull("IdentityInvalidUserName"); await _redisCacheService.ConnectAsync().ConfigureAwait(false); var cacheKey = $"pvc_{user.UserName}"; if (!(await _redisCacheService.KeyExistsAsync(cacheKey))) { throw new MilvaUserFriendlyException("ThereIsNoSavedVerificationCode"); } var verificationCodeInCache = await _redisCacheService.GetAsync(cacheKey).ConfigureAwait(false); if (verificationCode == verificationCodeInCache) { user.PhoneNumberConfirmed = true; return(await _userManager.UpdateAsync(user).ConfigureAwait(false)); } else { throw new MilvaUserFriendlyException("WrongPhoneNumberVerificationCode"); } }
/// <summary> /// Returns a tenant according to <paramref name="identifier"/>. /// </summary> /// <param name="identifier"></param> /// <returns></returns> public async Task <TTenant> GetTenantAsync(TKey identifier) { await _redisCacheService.CheckClientAndConnectIfNotAsync(); if (_redisCacheService.IsConnected()) { return(await _redisCacheService.GetAsync <TTenant>(identifier.ToString()).ConfigureAwait(false)); } else { return(null); } }
/// <summary> /// In memory check /// </summary> /// <param name="authId"></param> /// <param name="companyId"></param> /// <returns></returns> private async Task <bool> SpInMemoryCallToCheck(Guid authId, Guid companyId) { // "AuthIdAsKey" -> authId if (!_redisCacheService.TryGetValue(authId.ToString(), out IEnumerable <AuthCompanyDto> values)) //try get auth companies { values = await _efCoreService.FetchCompanies(authId); //cache it for 60 sec await _redisCacheService.SetAsync(authId.ToString(), values, 60); var authCachedRecord = await _redisCacheService.GetAsync <IEnumerable <AuthCompanyDto> >(authId.ToString()); authCachedRecord = authCachedRecord.Where(x => x.Id == companyId); if (!authCachedRecord.Any()) { return(false); } return(true); } else { var authCachedRecord = await _redisCacheService.GetAsync <IEnumerable <AuthCompanyDto> >(authId.ToString()); authCachedRecord = authCachedRecord.Where(x => x.Id == companyId); if (!authCachedRecord.Any()) { return(false); } return(true); } }