public SmsVerificationCodeEntity CreateSmsVerificationCode(string phone, string partnerId = null, bool generateRealCode = true, int codeLength = 4) { var creationDt = _dateTimeProvider.GetDateTime(); return(new SmsVerificationCodeEntity { RowKey = SmsVerificationCodeEntity.GenerateRowKey(creationDt), PartitionKey = SmsVerificationCodeEntity.GeneratePartitionKey(partnerId, phone), Code = _randomValueGenerator.GetCode(codeLength, generateRealCode), CreationDateTime = creationDt }); }
public async Task <ISmsVerificationCode> GetActualCode(string partnerId, string phoneNum) { var manualCode = await _manualCodesStorage.GetTopRecordAsync( SmsVerificationCodeEntity.GeneratePartitionKey(partnerId, phoneNum)); if (manualCode == null || manualCode.ExpirationDate < DateTime.UtcNow) { return(await _tableStorage.GetTopRecordAsync( SmsVerificationCodeEntity.GeneratePartitionKey(partnerId, phoneNum))); } return(manualCode); }
public SmsVerificationPriorityCodeEntity CreateSmsVerificationPriorityCode(string phone, string partnerId, DateTime expirationDt, int codeLength = 4) { var creationDt = _dateTimeProvider.GetDateTime(); return(new SmsVerificationPriorityCodeEntity { RowKey = SmsVerificationCodeEntity.GenerateRowKey(creationDt), PartitionKey = SmsVerificationCodeEntity.GeneratePartitionKey(partnerId, phone), Code = _randomValueGenerator.GetCode(codeLength, true), CreationDateTime = creationDt, ExpirationDate = expirationDt }); }
private static async Task DeleteCodesInRepository <T>(string partnerId, string phoneNum, INoSQLTableStorage <T> storage) where T : ITableEntity, new() { var batchOperation = new TableBatchOperation(); var entitiesToDelete = (await storage.GetDataAsync(SmsVerificationCodeEntity.GeneratePartitionKey(partnerId, phoneNum))) .ToArray(); if (entitiesToDelete.Any()) { foreach (var e in entitiesToDelete) { batchOperation.Delete(e); } await storage.DoBatchAsync(batchOperation); } }