Beispiel #1
0
        public async Task <OtpCode> CreateorUpdateOtpCodeAsync(string engagementAccount, string phoneNumber, string code, int expireTime)
        {
            using (var ctx = new OtpEntities(this.connectionString))
            {
                var otpCode = await ctx.OtpCodes.Where(f => f.EngagementAccount == engagementAccount && f.PhoneNumber == phoneNumber).SingleOrDefaultAsync();

                if (otpCode == null)
                {
                    otpCode = new OtpCode
                    {
                        PhoneNumber       = phoneNumber,
                        EngagementAccount = engagementAccount,
                        Code        = code,
                        CreatedTime = DateTime.UtcNow,
                        ExpiredTime = DateTime.UtcNow.AddSeconds(expireTime)
                    };
                    ctx.OtpCodes.Add(otpCode);
                }
                else
                {
                    otpCode.Code        = code;
                    otpCode.CreatedTime = DateTime.UtcNow;
                    otpCode.ExpiredTime = DateTime.UtcNow.AddSeconds(expireTime);
                }

                await ctx.SaveChangesAsync();

                return(otpCode);
            }
        }
Beispiel #2
0
 public async Task <OtpCode> QueryOtpCodeAsync(string engagementAccount, string phoneNumber)
 {
     using (var ctx = new OtpEntities(this.connectionString))
     {
         return(await ctx.OtpCodes.Where(f => f.EngagementAccount == engagementAccount && f.PhoneNumber == phoneNumber).SingleOrDefaultAsync());
     }
 }
Beispiel #3
0
        public async Task DeleteOtpAccountDataAsync(string account)
        {
            using (var ctx = new OtpEntities(this.connectionString))
            {
                var entities = await ctx.OtpCodes.Where(f => f.EngagementAccount == account).ToListAsync();

                if (entities == null || !entities.Any())
                {
                    return;
                }

                ctx.OtpCodes.RemoveRange(entities);
                await ctx.SaveChangesAsync();
            }
        }
Beispiel #4
0
        public async Task DeleteOtpCodeAsync(string engagementAccount, string phoneNumber)
        {
            using (var ctx = new OtpEntities(this.connectionString))
            {
                {
                    var entity = await ctx.OtpCodes.Where(f => f.EngagementAccount == engagementAccount && f.PhoneNumber == phoneNumber).SingleOrDefaultAsync();

                    if (entity == null)
                    {
                        return;
                    }

                    ctx.OtpCodes.Remove(entity);
                    await ctx.SaveChangesAsync();
                }
            }
        }
Beispiel #5
0
        public async Task DeleteOtpCodeByTimeAsync(DateTime expiredTime)
        {
            using (var ctx = new OtpEntities(this.connectionString))
            {
                {
                    // Delete records created 1 day ago
                    var entities = await ctx.OtpCodes.Where(f => f.ExpiredTime < expiredTime).ToListAsync();

                    if (entities == null || !entities.Any())
                    {
                        return;
                    }

                    ctx.OtpCodes.RemoveRange(entities);
                    await ctx.SaveChangesAsync();
                }
            }
        }