@@ -34,12 +34,12 @@ public class BlogPostController : DasBlogBaseController
34
34
private readonly ILogger < BlogPostController > logger ;
35
35
private readonly IBlogPostViewModelCreator modelViewCreator ;
36
36
private readonly IMemoryCache memoryCache ;
37
- private readonly IRecaptchaService recaptcha ;
37
+ private readonly IRecaptchaService recaptcha ;
38
38
39
39
40
- public BlogPostController ( IBlogManager blogManager , IHttpContextAccessor httpContextAccessor , IDasBlogSettings dasBlogSettings ,
40
+ public BlogPostController ( IBlogManager blogManager , IHttpContextAccessor httpContextAccessor , IDasBlogSettings dasBlogSettings ,
41
41
IMapper mapper , ICategoryManager categoryManager , IFileSystemBinaryManager binaryManager , ILogger < BlogPostController > logger ,
42
- IBlogPostViewModelCreator modelViewCreator , IMemoryCache memoryCache , IRecaptchaService recaptcha )
42
+ IBlogPostViewModelCreator modelViewCreator , IMemoryCache memoryCache , IRecaptchaService recaptcha )
43
43
: base ( dasBlogSettings )
44
44
{
45
45
this . blogManager = blogManager ;
@@ -51,7 +51,7 @@ public BlogPostController(IBlogManager blogManager, IHttpContextAccessor httpCon
51
51
this . logger = logger ;
52
52
this . modelViewCreator = modelViewCreator ;
53
53
this . memoryCache = memoryCache ;
54
- this . recaptcha = recaptcha ;
54
+ this . recaptcha = recaptcha ;
55
55
}
56
56
57
57
[ AllowAnonymous ]
@@ -177,7 +177,7 @@ public IActionResult EditPost(PostViewModel post, string submit)
177
177
178
178
if ( ! string . IsNullOrWhiteSpace ( post . NewCategory ) )
179
179
{
180
- ModelState . AddModelError ( nameof ( post . NewCategory ) ,
180
+ ModelState . AddModelError ( nameof ( post . NewCategory ) ,
181
181
$ "Please click 'Add' to add the category, \" { post . NewCategory } \" or clear the text before continuing") ;
182
182
return LocalRedirect ( string . Format ( "/post/{0}/edit" , post . EntryId ) ) ;
183
183
}
@@ -271,7 +271,7 @@ public IActionResult CreatePost(PostViewModel post, string submit)
271
271
}
272
272
273
273
if ( entry != null )
274
- {
274
+ {
275
275
logger . LogInformation ( new EventDataItem ( EventCodes . EntryAdded , null , "Blog post created: {0}" , entry . Title ) ) ;
276
276
}
277
277
@@ -375,11 +375,11 @@ public IActionResult CommentError(AddCommentViewModel comment, List<string> erro
375
375
AllowComments = entry . AllowComments
376
376
} ;
377
377
378
- if ( comment != null )
379
- lcvm . CurrentComment = comment ;
378
+ if ( comment != null )
379
+ lcvm . CurrentComment = comment ;
380
380
lpvm . Posts . First ( ) . Comments = lcvm ;
381
- if ( errors != null && errors . Count > 0 )
382
- lpvm . Posts . First ( ) . ErrorMessages = errors ;
381
+ if ( errors != null && errors . Count > 0 )
382
+ lpvm . Posts . First ( ) . ErrorMessages = errors ;
383
383
}
384
384
}
385
385
@@ -397,7 +397,7 @@ private IActionResult Comment(string posttitle)
397
397
[ HttpPost ( "post/comments" ) ]
398
398
public IActionResult AddComment ( AddCommentViewModel addcomment )
399
399
{
400
- List < string > errors = new List < string > ( ) ;
400
+ List < string > errors = new List < string > ( ) ;
401
401
402
402
if ( ! ModelState . IsValid )
403
403
{
@@ -410,30 +410,30 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
410
410
}
411
411
412
412
// Optional in case of Captcha. Commenting the settings in the config file
413
- // Will disable this check. People will typically disable this when using captcha.
414
- if ( ! string . IsNullOrEmpty ( dasBlogSettings . SiteConfiguration . CheesySpamQ ) &&
415
- ! string . IsNullOrEmpty ( dasBlogSettings . SiteConfiguration . CheesySpamA ) &&
416
- dasBlogSettings . SiteConfiguration . CheesySpamQ . Trim ( ) . Length > 0 &&
413
+ // Will disable this check. People will typically disable this when using captcha.
414
+ if ( ! string . IsNullOrEmpty ( dasBlogSettings . SiteConfiguration . CheesySpamQ ) &&
415
+ ! string . IsNullOrEmpty ( dasBlogSettings . SiteConfiguration . CheesySpamA ) &&
416
+ dasBlogSettings . SiteConfiguration . CheesySpamQ . Trim ( ) . Length > 0 &&
417
417
dasBlogSettings . SiteConfiguration . CheesySpamA . Trim ( ) . Length > 0 )
418
418
{
419
- if ( string . Compare ( addcomment . CheesyQuestionAnswered , dasBlogSettings . SiteConfiguration . CheesySpamA ,
419
+ if ( string . Compare ( addcomment . CheesyQuestionAnswered , dasBlogSettings . SiteConfiguration . CheesySpamA ,
420
420
StringComparison . OrdinalIgnoreCase ) != 0 )
421
421
{
422
- errors . Add ( "Answer to Spam Question is invalid. Please enter a valid answer for Spam Question and try again." ) ;
422
+ errors . Add ( "Answer to Spam Question is invalid. Please enter a valid answer for Spam Question and try again." ) ;
423
423
}
424
424
}
425
425
426
- if ( dasBlogSettings . SiteConfiguration . EnableCaptcha )
427
- {
428
- var recaptchaTask = recaptcha . Validate ( Request ) ;
429
- recaptchaTask . Wait ( ) ;
430
- var recaptchaResult = recaptchaTask . Result ;
431
- if ( ( ! recaptchaResult . success || recaptchaResult . score != 0 ) &&
432
- recaptchaResult . score < dasBlogSettings . SiteConfiguration . RecaptchaMinimumScore )
433
- {
434
- errors . Add ( "Unfinished Captcha. Please finish the captcha by clicking 'I'm not a robot' and try again." ) ;
435
- }
436
- }
426
+ if ( dasBlogSettings . SiteConfiguration . EnableCaptcha )
427
+ {
428
+ var recaptchaTask = recaptcha . Validate ( Request ) ;
429
+ recaptchaTask . Wait ( ) ;
430
+ var recaptchaResult = recaptchaTask . Result ;
431
+ if ( ( ! recaptchaResult . success || recaptchaResult . score != 0 ) &&
432
+ recaptchaResult . score < dasBlogSettings . SiteConfiguration . RecaptchaMinimumScore )
433
+ {
434
+ errors . Add ( "Unfinished Captcha. Please finish the captcha by clicking 'I'm not a robot' and try again." ) ;
435
+ }
436
+ }
437
437
438
438
if ( errors . Count > 0 )
439
439
{
@@ -446,7 +446,7 @@ public IActionResult AddComment(AddCommentViewModel addcomment)
446
446
commt . EntryId = Guid . NewGuid ( ) . ToString ( ) ;
447
447
commt . IsPublic = ! dasBlogSettings . SiteConfiguration . CommentsRequireApproval ;
448
448
commt . CreatedUtc = commt . ModifiedUtc = DateTime . Now . ToUniversalTime ( ) ;
449
-
449
+
450
450
logger . LogInformation ( new EventDataItem ( EventCodes . CommentAdded , null , "Comment CONTENT DUMP" , commt . Content ) ) ;
451
451
452
452
var state = blogManager . AddComment ( addcomment . TargetEntryId , commt ) ;
@@ -550,7 +550,7 @@ public IActionResult GetCategory(string category)
550
550
}
551
551
552
552
[ AllowAnonymous ]
553
- [ HttpPost ( "post/search" , Name = Constants . SearcherRouteName ) ]
553
+ [ HttpPost ( "post/search" , Name = Constants . SearcherRouteName ) ]
554
554
public IActionResult Search ( string searchText )
555
555
{
556
556
if ( string . IsNullOrWhiteSpace ( searchText ) )
@@ -561,7 +561,7 @@ public IActionResult Search(string searchText)
561
561
var lpvm = new ListPostsViewModel ( ) ;
562
562
var entries = blogManager . SearchEntries ( WebUtility . HtmlEncode ( searchText ) , Request . Headers [ "Accept-Language" ] ) ? . Where ( e => e . IsPublic ) ? . ToList ( ) ;
563
563
564
- if ( entries != null )
564
+ if ( entries != null )
565
565
{
566
566
lpvm . Posts = entries . Select ( entry => mapper . Map < PostViewModel > ( entry ) ) . ToList ( ) ;
567
567
ViewData [ Constants . ShowPageControl ] = false ;
@@ -579,15 +579,15 @@ private IActionResult HandleNewCategory(PostViewModel post)
579
579
ModelState . ClearValidationState ( "" ) ;
580
580
if ( string . IsNullOrWhiteSpace ( post . NewCategory ) )
581
581
{
582
- ModelState . AddModelError ( nameof ( post . NewCategory ) ,
582
+ ModelState . AddModelError ( nameof ( post . NewCategory ) ,
583
583
"To add a category you must enter some text in the box next to the 'Add' button before clicking 'Add'" ) ;
584
584
return View ( post ) ;
585
585
}
586
586
587
587
var newCategory = post . NewCategory ? . Trim ( ) ;
588
588
var newCategoryDisplayName = newCategory ;
589
589
var newCategoryUrl = NBR . Entry . InternalCompressTitle ( newCategory ) ;
590
- // Category names should not include special characters #200
590
+ // Category names should not include special characters #200
591
591
if ( post . AllCategories . Any ( c => c . CategoryUrl == newCategoryUrl ) )
592
592
{
593
593
ModelState . AddModelError ( nameof ( post . NewCategory ) , $ "The category, { post . NewCategory } , already exists") ;
@@ -596,7 +596,7 @@ private IActionResult HandleNewCategory(PostViewModel post)
596
596
{
597
597
post . AllCategories . Add ( new CategoryViewModel { Category = newCategoryDisplayName , CategoryUrl = newCategoryUrl , Checked = true } ) ;
598
598
post . NewCategory = "" ;
599
- ModelState . Remove ( nameof ( post . NewCategory ) ) ; // ensure response refreshes page with view model's value
599
+ ModelState . Remove ( nameof ( post . NewCategory ) ) ; // ensure response refreshes page with view model's value
600
600
}
601
601
602
602
return View ( post ) ;
@@ -608,7 +608,7 @@ private IActionResult HandleImageUpload(PostViewModel post)
608
608
var fileName = post . Image ? . FileName ;
609
609
if ( string . IsNullOrEmpty ( fileName ) )
610
610
{
611
- ModelState . AddModelError ( nameof ( post . Image ) ,
611
+ ModelState . AddModelError ( nameof ( post . Image ) ,
612
612
$ "You must select a file before clicking \" { Constants . UploadImageAction } \" to upload it") ;
613
613
return View ( post ) ;
614
614
}
@@ -643,7 +643,7 @@ private void ValidatePostName(PostViewModel post)
643
643
var dt = ValidatePostDate ( post ) ;
644
644
var entry = blogManager . GetBlogPost ( post . Title . Replace ( " " , string . Empty ) , dt ) ;
645
645
646
- if ( entry != null && string . Compare ( entry . EntryId , post . EntryId , true ) > 0 )
646
+ if ( entry != null && string . Compare ( entry . EntryId , post . EntryId , true ) > 0 )
647
647
{
648
648
ModelState . AddModelError ( string . Empty , "A post with this title already exists. Titles must be unique" ) ;
649
649
}
@@ -680,6 +680,7 @@ private void BreakSiteCache()
680
680
{
681
681
memoryCache . Remove ( CACHEKEY_RSS ) ;
682
682
memoryCache . Remove ( CACHEKEY_FRONTPAGE ) ;
683
+ memoryCache . Remove ( CACHEKEY_ARCHIVE ) ;
683
684
}
684
685
685
686
}
0 commit comments