/// <summary> /// 创建一个新的验证码 /// </summary> /// <param name="authenticationType"></param> /// <param name="codeLength"></param> /// <returns></returns> public static AuthenticationCode Create(string authenticationType, int codeLength) { authenticationType.CheckStringIsNullOrEmpty("authenticationType"); AuthenticationCode result = new AuthenticationCode(); result.AuthenticationID = UuidHelper.NewUuidString(); result.AuthenticationType = authenticationType; result.Code = GenerateCode(codeLength); return(result); }
/// <summary> /// 颁发认证码 /// </summary> /// <param name="authenticationType"></param> /// <param name="codeLength"></param> /// <returns></returns> public AuthenticationCode IssueCode(string authenticationType, int codeLength) { AuthenticationCode result = AuthenticationCode.Create(authenticationType, codeLength); InsertSqlClauseBuilder builder = ORMapping.GetInsertSqlClauseBuilder(result); builder.AppendItem("EXPIRE_TIME", string.Format("DATEADD(second, {0}, GETDATE())", 1800), "=", true); string sql = string.Format("INSERT INTO {0} {1}", this.GetMappingInfo().TableName, builder.ToSqlString(TSqlBuilder.Instance)); ExecuteNonQuery(sql); return(result); }
/// <summary> /// 重发一个新的Code。 /// </summary> /// <param name="authenticationID"></param> /// <param name="codeLength"></param> /// <returns>重新生成的Code</returns> public string ReissueCode(string authenticationID, int codeLength) { string result = AuthenticationCode.GenerateCode(codeLength); UpdateSqlClauseBuilder builder = new UpdateSqlClauseBuilder(); builder.AppendItem("AUTHENTICATION_CODE", result); builder.AppendItem("EXPIRE_TIME", string.Format("DATEADD(second, {0}, GETDATE())", 1800), "=", true); string sql = string.Format("UPDATE {0} SET {1} WHERE AUTHENTICATION_ID = {2}", this.GetMappingInfo().TableName, builder.ToSqlString(TSqlBuilder.Instance), TSqlBuilder.Instance.CheckUnicodeQuotationMark(authenticationID)); ExecuteNonQuery(sql); return(result); }
private AuthenticationCode Query(string sql) { AuthenticationCode result = null; using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { Database db = DatabaseFactory.Create(this.GetConnectionName()); DataTable table = db.ExecuteDataSet(CommandType.Text, sql).Tables[0]; if (table.Rows.Count > 0) { result = new AuthenticationCode(); ORMapping.DataRowToObject(table.Rows[0], result); } } return(result); }
/// <summary> /// 创建一个新的验证码 /// </summary> /// <param name="authenticationType"></param> /// <param name="codeLength"></param> /// <returns></returns> public static AuthenticationCode Create(string authenticationType, int codeLength) { authenticationType.CheckStringIsNullOrEmpty("authenticationType"); AuthenticationCode result = new AuthenticationCode(); result.AuthenticationID = UuidHelper.NewUuidString(); result.AuthenticationType = authenticationType; result.Code = GenerateCode(codeLength); return result; }
private AuthenticationCode Query(string sql) { AuthenticationCode result = null; using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { Database db = DatabaseFactory.Create(this.GetConnectionName()); DataTable table = db.ExecuteDataSet(CommandType.Text, sql).Tables[0]; if (table.Rows.Count > 0) { result = new AuthenticationCode(); ORMapping.DataRowToObject(table.Rows[0], result); } } return result; }