JordanRift.Grassroots.Web.Controllers.AccountController.Activate C# (CSharp) Method

Activate() public method

Check if activation hash is valid. * If yes, set user profile IsActivated to true and redirect to login * If no, redirect to AwaitingActivation
public Activate ( string hash, string redirect = "" ) : System.Web.Mvc.RedirectToRouteResult
hash string ashed string to compare
redirect string
return System.Web.Mvc.RedirectToRouteResult
        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");
        }