/// <summary>CreateCustomizedConfirmationData</summary> /// <param name="userID">string</param> /// <param name="CustomizedConfirmationJson">customizedConfirmationJson</param> public void CreateCustomizedConfirmationData(string userID, CustomizedConfirmationJson customizedConfirmationJson) { string json = JsonConvert.SerializeObject(customizedConfirmationJson); switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.Memory: // Memoryでは、有効期限のチェックはしない。 string temp = ""; CustomizedConfirmationProvider.CustomizedConfirmationData.TryRemove(userID, out temp); CustomizedConfirmationProvider.CustomizedConfirmationData.TryAdd(userID, json); break; case EnumUserStoreType.SqlServer: case EnumUserStoreType.ODPManagedDriver: case EnumUserStoreType.PostgreSQL: // DMBMS using (IDbConnection cnn = DataAccess.CreateConnection()) { cnn.Open(); switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.SqlServer: cnn.Execute("DELETE FROM [CustomizedConfirmation] WHERE [UserId] = @UserId", new { UserId = userID }); cnn.Execute( "INSERT INTO [CustomizedConfirmation] ([UserId], [Value], [CreatedDate]) VALUES (@UserId, @Value, @CreatedDate)", new { UserId = userID, Value = json, CreatedDate = DateTime.Now }); break; case EnumUserStoreType.ODPManagedDriver: cnn.Execute("DELETE FROM \"CustomizedConfirmation\" WHERE \"UserId\" = :UserId", new { UserId = userID }); cnn.Execute( "INSERT INTO \"CustomizedConfirmation\" (\"UserId\", \"Value\", \"CreatedDate\") VALUES (:UserId, :Value, :CreatedDate)", new { UserId = userID, Value = json, CreatedDate = DateTime.Now }); break; case EnumUserStoreType.PostgreSQL: cnn.Execute("DELETE FROM \"customizedconfirmation\" WHERE \"userid\" = @UserId", new { UserId = userID }); cnn.Execute( "INSERT INTO \"customizedconfirmation\" (\"userid\", \"value\", \"createddate\") VALUES (@UserId, @Value, @CreatedDate)", new { UserId = userID, Value = json, CreatedDate = DateTime.Now }); break; } } break; } }
/// <summary>CheckCustomizedConfirmationData</summary> /// <param name="userID">string</param> /// <param name="code">string</param> /// <param name="isExpired">string</param> public string CheckCustomizedConfirmationData(string userID, string code, out bool isExpired) { isExpired = false; CustomizedConfirmationJson customizedConfirmationJson = null; switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.Memory: string temp = ""; CustomizedConfirmationProvider.CustomizedConfirmationData.TryRemove(userID, out temp); if (string.IsNullOrEmpty(temp)) { return(""); } // Memoryでは、有効期限のチェックはしない。 customizedConfirmationJson = (CustomizedConfirmationJson)JsonConvert.DeserializeObject <CustomizedConfirmationJson>(temp); if (code == customizedConfirmationJson.Code) { return(customizedConfirmationJson.Email); } else { return(""); } //break; case EnumUserStoreType.SqlServer: case EnumUserStoreType.ODPManagedDriver: case EnumUserStoreType.PostgreSQL: // DMBMS CustomizedConfirmationRet customizedConfirmationRet = null; IEnumerable <CustomizedConfirmationRet> customizedConfirmationRets = null; using (IDbConnection cnn = DataAccess.CreateConnection()) { cnn.Open(); switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.SqlServer: customizedConfirmationRets = cnn.Query <CustomizedConfirmationRet>( "SELECT [Value], [CreatedDate] FROM [CustomizedConfirmation] WHERE [UserId] = @UserId", new { UserId = userID }); cnn.Execute("DELETE FROM [CustomizedConfirmation] WHERE [UserId] = @UserId", new { UserId = userID }); break; case EnumUserStoreType.ODPManagedDriver: customizedConfirmationRets = cnn.Query <CustomizedConfirmationRet>( "SELECT \"Value\", \"CreatedDate\" FROM \"CustomizedConfirmation\" WHERE \"UserId\" = :UserId", new { UserId = userID }); cnn.Execute("DELETE FROM \"CustomizedConfirmation\" WHERE \"UserId\" = :UserId", new { UserId = userID }); break; case EnumUserStoreType.PostgreSQL: customizedConfirmationRets = cnn.Query <CustomizedConfirmationRet>( "SELECT \"value\", \"createddate\" FROM \"customizedconfirmation\" WHERE \"userid\" = @UserId", new { UserId = userID }); cnn.Execute("DELETE FROM \"customizedconfirmation\" WHERE \"userid\" = @UserId", new { UserId = userID }); break; } } // 件数チェック if (customizedConfirmationRets.AsList().Count == 0) { return(""); } // 有効期限のチェック customizedConfirmationRet = customizedConfirmationRets.AsList()[0]; if (DateTime.Now <= customizedConfirmationRet.CreatedDate.Add(ASPNETIdentityConfig.EmailConfirmationTokenLifespanFromHours)) { customizedConfirmationJson = (CustomizedConfirmationJson)JsonConvert.DeserializeObject <CustomizedConfirmationJson>(customizedConfirmationRet.Value); if (code == customizedConfirmationJson.Code) { return(customizedConfirmationJson.Email); } else { return(""); } } else { isExpired = true; return(""); } //break; } return(""); }