public bool CheckValidationCode(string mobile, string category, string validateCode, int maxRetryTime) { bool isSuccess; using (var biz = new ValidationMobileBusinessManagement()) { biz.BeginTran(); using (var manager = new MobileValidationManager()) { var validation = manager.GetMobileValidation(mobile, category); if (validation == null) { throw new Exception("尚未发送验证码"); } manager.AddMobileValidationLog(new MobileValidationLog { CreateTime = DateTime.Now, DB_ValidateCode = validation.ValidateCode, Mobile = mobile, User_ValidateCode = validateCode, }); if (validation.RetryTimes >= maxRetryTime) { throw new Exception(string.Format("重试次数超出最大限制次数【{0}】次,请尝试重新发送验证码。", maxRetryTime)); } if (validation.ValidateCode == validateCode) { manager.DeleteMobileValidation(validation); isSuccess = true; } else { validation.RetryTimes++; manager.UpdateMobileValidation(validation); isSuccess = false; } } biz.CommitTran(); } return(isSuccess); }
public void RefreshValidationStatus(string mobile, string category) { using (var biz = new ValidationMobileBusinessManagement()) { biz.BeginTran(); using (var manager = new MobileValidationManager()) { var validation = manager.GetMobileValidation(mobile, category); if (validation == null) { throw new Exception("验证码不存在,可能是已经通过验证"); } validation.SendTimes = 1; validation.RetryTimes = 0; manager.UpdateMobileValidation(validation); } biz.CommitTran(); } }
public void DeleteValidation(string mobile, string category, int delaySeconds, string delayDescription) { using (var biz = new ValidationMobileBusinessManagement()) { biz.BeginTran(); using (var manager = new MobileValidationManager()) { var validation = manager.GetMobileValidation(mobile, category); if (validation == null) { throw new Exception("验证码不存在,可能是已经通过验证"); } var span = validation.UpdateTime.AddSeconds(delaySeconds) - DateTime.Now; if (span.TotalSeconds > 0) { throw new Exception(string.Format("删除验证码必须距上次验证码操作【{0}】以上,验证码上次操作时间【{1:yyyy-MM-dd HH:mm:ss}】。", delayDescription, validation.UpdateTime)); } manager.DeleteMobileValidation(validation); } biz.CommitTran(); } }