1: /// <summary>
2: /// Checks if the IP or email is blacklisted
3: /// </summary>
4: /// <param name="IP">The IP of the user</param>
5: /// <param name="Email">The Email of the user</param>
6: /// <returns>true if blacklisted, false if whitelisted, or null if undetermined</returns>
7: public static Nullable<bool> IsBlacklisted(string IP, string Email)
8: {
9: int blackCnt = 0;
10: int whiteCnt = 0;
11:
12: // check if this user already has approved or
13: // rejected comments and belongs to white/black list
14: foreach (Post p in Post.Posts)
15: {
16: foreach (Comment c in p.Comments)
17: {
18: if (
19: ( Email != String.Empty && c.Email.ToLowerInvariant() == Email.ToLowerInvariant())
20: || c.IP == IP
21: )
22: {
23: if (c.IsApproved)
24: whiteCnt++;
25: else
26: blackCnt++;
27: }
28: }
29: }
30:
31: // user is in the white list - approve comment
32: if (whiteCnt >= BlogSettings.Instance.CommentWhiteListCount)
33: {
34: return false;
35: }
36:
37: // user is in the black list - reject comment
38: if (blackCnt >= BlogSettings.Instance.CommentBlackListCount)
39: {
40: return true;
41: }
42:
43: return null;
44: }
45:
46: static bool ModeratedByRule(Comment comment)
47: {
48: // trust authenticated users
49: if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
50: {
51: comment.IsApproved = true;
52: comment.ModeratedBy = "Rule:authenticated";
53: return true;
54: }
55:
56: Nullable<bool> isBlacklisted = IsBlacklisted(comment.IP, comment.Email);
57:
58: // user is in the white list - approve comment
59: if (isBlacklisted == false)
60: {
61: comment.IsApproved = true;
62: comment.ModeratedBy = "Rule:white list";
63: return true;
64: }
65:
66: // user is in the black list - reject comment
67: if (isBlacklisted == true)
68: {
69: comment.IsApproved = false;
70: comment.ModeratedBy = "Rule:black list";
71: return true;
72: }
73: return false;
74: }