public RedirectToRouteResult Activate(string hash, string redirect = "")
{
if (hash == null)
{
return RedirectToAction("AwaitingActivation", "Account", new { returnUrl = redirect });
}
using (userProfileRepository)
{
var userProfile = userProfileRepository.GetUserProfileByActivationHash(hash);
var organization = OrganizationRepository.GetDefaultOrganization(readOnly: true);
var service = new GrassrootsMembershipService();
if (userProfile == null)
{
TempData["UserFeedback"] = "Are you sure you have an account here?";
return RedirectToAction("Register", new { returnUrl = redirect });
}
if (service.IsActivationHashValid(userProfile))
{
userProfile.IsActivated = true;
// Check for existing donations
var previousDonations = from d in campaignDonorRepository.FindAllDonations()
where d.Email == userProfile.Email
&& d.UserProfile == null
select d;
foreach (var donation in previousDonations)
{
donation.UserProfileID = userProfile.UserProfileID;
}
campaignDonorRepository.Save();
userProfileRepository.Save();
TempData["UserFeedback"] = "Sweet! Your account is activated. Please log in.";
accountMailer.Welcome(MapWelcomeModel(userProfile, organization)).SendAsync();
return RedirectToAction("LogOn", "Account", new { returnUrl = redirect });
}
}
TempData["UserFeedback"] = "Looks like your activation request may have expired. Complete the form below to try again.";
return RedirectToAction("AwaitingActivation", "Account");
}