My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes    
 
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.Net;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using AdamDotCom.Common.Website;
using AdamDotCom.Website.App.Extensions;
using AdamDotCom.Whois.Service.Proxy;

namespace AdamDotCom.Website.App.Controllers
{
[HandleError]
public class ContactController : Controller
{
private readonly IWhois whoisService;
private readonly IMailer mailer;

public ContactController() : this(new WhoisService(), new Mailer()) {}

public ContactController(IWhois whoisService, IMailer mailer)
{
this.whoisService = whoisService;
this.mailer = mailer;
}

public ActionResult Thanks()
{
return View();
}

public ActionResult IsFriendly()
{
if (HttpContext.Request != null)
{
var ipAddress = HttpContext.Request.UserHostAddress;
var referrer = (HttpContext.Request.UrlReferrer != null) ? HttpContext.Request.UrlReferrer.ToString() : string.Empty;

var whois = whoisService.WhoisEnhancedXml(ipAddress, "Canada,Calgary,Alberta", referrer);

if (whois.IsFriendly || whois.IsFilterMatch)
{
return Content(string.Format("mailto:{0}?subject=I found your site and...", MyWebPresence.EmailAccount));
}
}

Response.StatusCode = (int) HttpStatusCode.BadRequest;
return Content("Unknown");
}

public ActionResult Index()
{
return View();
}

[AcceptVerbs(HttpVerbs.Post), ValidateAntiForgeryToken, ValidateInput(false)]
public ActionResult Send()
{
MailerMessage mailerMessage = GetMailerMessage();

if(!mailerMessage.IsValid())
{
HttpContext.Response.StatusCode = (int) HttpStatusCode.NotAcceptable;
return Content("Your <span>email</span> and <span>message</span> are required, ensure those fields are correct. Then try, try, try again.");
}

mailerMessage.AppendWhois(whoisService, HttpContext.Request.UserHostAddress);

if(mailer.Send(mailerMessage))
{
return RedirectToAction("Thanks");
}

if(mailer.Errors.Count != 0)
{
HttpContext.Response.StatusCode = (int) HttpStatusCode.BadRequest;
return Content("The server gremlins are at it again! they marked your message as spam. Check that your <span>email</span> is valid and that the <span>message</span> doesn't contain any weird characters. Thanks!");
}

HttpContext.Response.StatusCode = (int) HttpStatusCode.InternalServerError;
return Content(string.Format("Now that's embarrassing. You found a bug! Let's take this off my site, here's email address {0}. Thanks!", MyWebPresence.EmailLink));
}

private MailerMessage GetMailerMessage()
{
var mailerMessage = new MailerMessage();
TryUpdateModel(mailerMessage);
mailerMessage.Subject = string.Format("Adam.Kahtava.com response :: {0}", mailerMessage.Subject);
mailerMessage.ToAddress = MyWebPresence.EmailAccount;
mailerMessage.ToName = MyWebPresence.FullName;
return mailerMessage;
}
}
}

Change log

r99 by adam.kahtava.com on Jun 9, 2010   Diff
Copy updates, added contact-me overlay
(now friendly visitors can email directly
instead of going through the form)
Go to: 
Sign in to write a code review

Older revisions

r98 by adam.kahtava.com on Jun 9, 2010   Diff
Updated tests to use Model binding
instead of ViewData
r95 by adam.kahtava.com on Jun 6, 2010   Diff
Additional test coverage
r90 by adam.kahtava.com on Mar 28, 2010   Diff
Fixed a typo in error messages, added
filtering for hrefs in email body, RSS
to entire site.
All revisions of this file

File info

Size: 3512 bytes, 91 lines
Powered by Google Project Hosting