コード例 #1
0
        public async Task <string> GenerateResetIdentifierAsync(string adminId)
        {
            string   identifier;
            TimeSpan identifierTimeSpan;

            try
            {
                (identifier, identifierTimeSpan) = await _resetIdentifierService.GenerateAsync(adminId);
            }
            catch (IdentifierRequestsExceededException)
            {
                _log.Warning("Too much admin password reset identifier requests", context: $"adminId: {adminId}");
                throw;
            }

            await _passwordResetRepository.CreateOrUpdateIdentifierAsync(adminId, identifier, identifierTimeSpan);

            _log.Info("Admin password reset identifier generated",
                      context: $"adminId: {adminId}; valid until: {DateTime.UtcNow + identifierTimeSpan}");

            return(identifier);
        }
コード例 #2
0
        public async Task <PasswordResetModel> CreateOrUpdateIdentifierAsync(string customerId)
        {
            await RecordCallAsync(customerId);

            if (await GetCallsForPeriodAsync(customerId) > _maxAllowedRequestsNumber)
            {
                _log.Info($"Customer with Id: {customerId} made to many Password reset request and was blocked");
                return(new PasswordResetModel {
                    ErrorCode = PasswordResetErrorCodes.ReachedMaximumRequestForPeriod
                });
            }

            var identifier = GenerateIdentifier(customerId, _resetIdentifierLength);
            await _passwordResetRepository.CreateOrUpdateIdentifierAsync(customerId, identifier, _identifierTimeSpan);

            _log.Info(
                $"Successfully generated and updated Password Reset Identifier for Customer: {customerId} which will be valid till {DateTime.UtcNow + _identifierTimeSpan}");

            return(new PasswordResetModel
            {
                ErrorCode = PasswordResetErrorCodes.None,
                Identifier = identifier
            });
        }