GetUserAuthorizationHash() public method

public GetUserAuthorizationHash ( ) : string
return string
Ejemplo n.º 1
0
        public ActionResult RegisterUser(FacebookRegisterModel model, string returnUrl)
        {
            // TODO: Rebuild functionality using CoffeeScript implementation and new C# API
            if (ModelState.IsValid)
            {
                var userProfile = Mapper.Map<FacebookRegisterModel, UserProfile>(model);

                using (new UnitOfWorkScope())
                {
                    var userProfileService = new UserProfileService(userProfileRepository);
                    var organization = OrganizationRepository.GetDefaultOrganization(readOnly: false);

                    if (!userProfileService.IsFacebookAccountUnique(userProfile.FacebookID))
                    {
                        TempData["ModelErrors"] = new List<string> { "This FacebookID is already in use by another user account. Please sign in with a different Facebook account." };
                        return RedirectToAction("Register", new { returnUrl = returnUrl });
                    }

                    if (organization.UserProfiles == null)
                    {
                        organization.UserProfiles = new List<UserProfile>();
                    }

                    userProfile.Active = true;
                    userProfile.IsActivated = false;
                    var service = new GrassrootsMembershipService();
                    userProfile.ActivationHash = service.GetUserAuthorizationHash();
                    userProfile.LastActivationAttempt = DateTime.Now;
                    organization.UserProfiles.Add(userProfile);
                    OrganizationRepository.Save();
                    accountMailer.Authorize(new AuthorizeModel
                                                {
                                                    Email = userProfile.Email,
                                                    FirstName = userProfile.FirstName,
                                                    LastName = userProfile.LastName,
                                                    SenderEmail = organization.ContactEmail,
                                                    SenderName = organization.Name,
                                                    Url = Url.ToPublicUrl(Url.Action("Activate", "Account", new { hash = userProfile.ActivationHash }))
                                                }).SendAsync();

                    return RedirectToAction("AwaitingActivation", "Account");
                }
            }

            return RedirectToAction("Register");
        }
Ejemplo n.º 2
0
        public ActionResult RegisterUser(FacebookRegisterModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var userProfile = Mapper.Map<FacebookRegisterModel, UserProfile>(model);

                using (new UnitOfWorkScope())
                {
                    var organization = OrganizationRepository.GetDefaultOrganization(readOnly: false);

                    if (organization.UserProfiles == null)
                    {
                        organization.UserProfiles = new List<UserProfile>();
                    }

                    userProfile.Active = true;
                    userProfile.IsActivated = false;
                    var service = new GrassrootsMembershipService();
                    userProfile.ActivationHash = service.GetUserAuthorizationHash();
                    userProfile.LastActivationAttempt = DateTime.Now;
                    organization.UserProfiles.Add(userProfile);
                    OrganizationRepository.Save();
                    accountMailer.Authorize(new AuthorizeModel
                                                {
                                                    Email = userProfile.Email,
                                                    FirstName = userProfile.FirstName,
                                                    LastName = userProfile.LastName,
                                                    SenderEmail = organization.ContactEmail,
                                                    SenderName = organization.Name,
                                                    Url = Url.ToPublicUrl(Url.Action("Activate", "Account", new { hash = userProfile.ActivationHash }))
                                                }).SendAsync();

                    return RedirectToAction("AwaitingActivation", "Account");
                }
            }

            return RedirectToAction("Register");
        }
Ejemplo n.º 3
0
        public ActionResult SendAuthorizationNote(AuthorizeModel model)
        {
            using (userProfileRepository)
            {
                var userProfile = userProfileRepository.FindUserProfileByEmail(model.Email).FirstOrDefault();
                var organization = OrganizationRepository.GetDefaultOrganization(readOnly: true);

                if (userProfile == null)
                {
                    TempData["UserFeedback"] = "We couldn't find that email address in our system. Are you sure that was the right one?";
                    return RedirectToAction("AwaitingActivation", "Account");
                }

                var service = new GrassrootsMembershipService();
                userProfile.ActivationHash = service.GetUserAuthorizationHash();
                userProfile.LastActivationAttempt = DateTime.Now;
                userProfileRepository.Save();
                accountMailer.Authorize(MapAuthorizeModel(userProfile, organization)).SendAsync();
            }

            TempData["UserFeedback"] = "We just sent you an email. Check your email account and follow the instructions inside.";
            return RedirectToAction("AwaitingActivation", "Account");
        }
Ejemplo n.º 4
0
        public ActionResult SendPasswordReset(ForgotPasswordModel model)
        {
            if (ModelState.IsValid)
            {
                using (userProfileRepository)
                {
                    var userProfile = userProfileRepository.FindUserProfileByEmail(model.Email).FirstOrDefault();

                    if (userProfile != null)
                    {
                        var service = new GrassrootsMembershipService();
                        userProfile.ActivationHash = service.GetUserAuthorizationHash();
                        userProfile.ActivationPin = service.GenerateRandomPin();
                        userProfile.LastActivationAttempt = DateTime.Now;
                        userProfileRepository.Save();
                        accountMailer.PasswordReset(MapPasswordReset(userProfile)).SendAsync();

                        return RedirectToAction("UpdatePassword", new { hash = userProfile.ActivationHash });
                    }
                }

                TempData["UserFeedback"] = "The email you are looking for could not be found in our system.";
            }

            TempData["ForgotPasswordModel"] = model;
            return RedirectToAction("ForgotPassword");
        }
Ejemplo n.º 5
0
        public ActionResult RegisterUser(RegisterModel model, string returnUrl = "")
        {
            if (ModelState.IsValid)
            {
                MembershipCreateStatus status;
                UserProfile userProfile;
                Organization organization;

                using (new UnitOfWorkScope())
                using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    // This should ensure best compatiblity through a variety of SQL database environments
                    // (e.g. - SQL Server, MySQL, SQL Azure).
                    userProfile = Mapper.Map<RegisterModel, UserProfile>(model);
                    organization = OrganizationRepository.GetDefaultOrganization(readOnly: false);

                    if (organization.UserProfiles == null)
                    {
                        organization.UserProfiles = new List<UserProfile>();
                    }

                    userProfile.Active = true;
                    userProfile.IsActivated = false;
                    var service = new GrassrootsMembershipService();
                    userProfile.ActivationHash = service.GetUserAuthorizationHash();
                    userProfile.LastActivationAttempt = DateTime.Now;
                    organization.UserProfiles.Add(userProfile);
                    OrganizationRepository.Save();
                    status = MembershipService.CreateUser(model.Email, model.Password, model.Email);
                    transactionScope.Complete();
                }

                if (status == MembershipCreateStatus.Success)
                {
                    accountMailer.Authorize(MapAuthorizeModel(userProfile, organization, returnUrl)).SendAsync();

                    return RedirectToAction("AwaitingActivation", "Account");
                }
            }

            var url = returnUrl;
            TempData["RegisterModel"] = model;
            TempData["ModelErrors"] = FindModelErrors();
            return RedirectToAction("Register", "Account", new { returnUrl = url });
        }