forked from wojilu/wojilu
/
SecurityController.cs
executable file
·72 lines (47 loc) · 1.84 KB
/
SecurityController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright (c) 2010, www.wojilu.com. All rights reserved.
*/
using System;
using System.Text;
using System.Reflection;
using wojilu.ORM;
using wojilu.Web.Mvc;
using wojilu.Apps.Forum.Domain;
using wojilu.Apps.Forum.Service;
using wojilu.Web.Controller.Forum.Utils;
namespace wojilu.Web.Controller.Forum {
public class SecurityController : ControllerBase {
public Random rd = new Random();
public override void CheckPermission() {
if (!checkRegisterTimeValid()) return;
ForumApp forum = ctx.app.obj as ForumApp;
refreshTodayStats( forum );
}
private void refreshTodayStats( ForumApp forum ) {
if (time.IsNextDay( forum.TodayTime ) == false) return;
int all = forum.TodayTopicCount + forum.TodayPostCount;
if (all > forum.PeakPostCount) {
forum.PeakPostCount = all;
}
forum.YestodayPostCount = forum.TodayTopicCount + forum.TodayPostCount;
forum.TodayPostCount = 0;
forum.TodayTopicCount = 0;
forum.TodayVisitCount = 0;
forum.TodayTime = DateTime.Now;
forum.update();
ForumBoard.updateBatch( "set TodayTopics=0, TodayPosts=0", "AppId=" + forum.Id );
}
//--------------------------------------------------------------------------------------
// TODO 需要配置
private Boolean checkRegisterTimeValid() {
if (ctx.HttpMethod.Equals( "GET" )) return true;
int validHours = 0;
TimeSpan span = DateTime.Now.Subtract( ctx.viewer.obj.Created );
if (span.Hours < validHours) {
echoRedirect( string.Format( lang( "exPostAfter" ), validHours ) );
return false;
}
return true;
}
}
}