コード例 #1
0
        public async Task <IResponse> SendForgotPasswordAsync(string email, Uri resetPasswordPageLink, CancellationToken cancellationToken)
        {
            var user = await _userRepository.GetByEmailAsync(email, cancellationToken);

            if (user == null)
            {
                return(new NotFoundResponse("Email is not found!"));
            }

            var temporaryRandomString = Guid.NewGuid().ToString();

            var cacheObject = new CacheObject <Guid>()
            {
                Key          = temporaryRandomString,
                Value        = user.Id,
                TimeToExpire = _resetPasswordSettings.TimeToExpireSecretString
            };
            await _cache.AddAsync(cacheObject, cancellationToken);

            var uriBuilder = new UriBuilder(resetPasswordPageLink);
            var query      = HttpUtility.ParseQueryString(uriBuilder.Query);

            query["secretString"] = temporaryRandomString;
            uriBuilder.Query      = query.ToString() ?? string.Empty;

            var forgotPasswordPage = _stringLocalizer["ForgotPasswordPage"].ToString();

            var pageWithParams = forgotPasswordPage.Replace("{link}", uriBuilder.ToString());

            await _emailService.SendEmailAsync("Reset your password", pageWithParams, email, cancellationToken);

            return(new OkResponse());
        }
コード例 #2
0
        protected override async Task ExcecuteAsync(ICacheManager <string> cache)
        {
            var cacheItem = new CacheItem <string>(_key, "region", "value");

            if (!await cache.AddAsync(cacheItem))
            {
                await cache.RemoveAsync(_key);
            }
        }
コード例 #3
0
        public async Task AddAsync(RefreshToken refreshToken, CancellationToken cancellationToken)
        {
            var cacheObject = new CacheObject <Guid>
            {
                Key          = refreshToken.Token,
                Value        = refreshToken.UserId,
                TimeToExpire = _jwtSecret.TimeToExpireRefreshToken
            };

            await _cacheManager.AddAsync(cacheObject, cancellationToken);
        }
コード例 #4
0
        /// <inheritdoc />
        public async Task Add <TAggregateRoot>(TAggregateRoot[] instances) where TAggregateRoot : IAggregateRoot
        {
            if (instances == null)
            {
                throw new ArgumentNullException(nameof(instances));
            }

            if (!instances.Any())
            {
                return;
            }

            var repository = (IRepository <TAggregateRoot>)_instances.GetOrAdd(typeof(TAggregateRoot), t => _componentContext.Resolve <IRepository <TAggregateRoot> >());

            if (repository == null)
            {
                throw new InvalidOperationException($"No repository has been registered for type {typeof(TAggregateRoot)}.");
            }

            await repository.Add(instances);

            await _cacheManager.AddAsync(instances);
        }
コード例 #5
0
        public async Task <TResult> Handle(TRequest request, CancellationToken cancellationToken)
        {
            try
            {
                Logger.LogInformation($"Execute handler {typeof(TRequest).Name} with parameter {request.ToJsonString()}");

                var result = await _cacheManager.GetAsync <TResult>(GetCacheKey(request));

                if (result == null)
                {
                    result = await ExecuteAsync(request, cancellationToken);

                    await _cacheManager.AddAsync(result, GetCacheKey(request), _customCacheExpirationTime);
                }

                return(result);
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error occured in {typeof(TRequest).Name} handler", ex);
                throw;
            }
        }
コード例 #6
0
 public Task SetAsync(string key, IEnumerable <Claim> item)
 {
     return(cacheClient.AddAsync(key, item, TimeSpan.FromMinutes(30)));
 }
コード例 #7
0
 public Task SetAsync(string key, IEnumerable <Scope> item)
 {
     return(cacheClient.AddAsync(key, item, TimeSpan.FromHours(2)));
 }
 public Task SetAsync(string key, Client item)
 {
     return(cacheClient.AddAsync(key, item, TimeSpan.FromHours(2)));
 }