Ejemplo n.º 1
0
        public ActionResult Signup(string firstName, string lastName, string email)
        {
            // Do we have all the data we need?
            if (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(lastName) || string.IsNullOrEmpty(email))
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            MembershipCreateStatus createStatus;

            WebSite.Infrastructure.MembershipProvider membershipProvider = Membership.Provider as WebSite.Infrastructure.MembershipProvider;

            int memberId = membershipProvider.CreateStockwinnersMember(email, "stockwinners", firstName, lastName, out createStatus);

            if (createStatus == MembershipCreateStatus.Success)
            {
                Authentication.SetCurrentUser(new LoggedInUserIdentity()
                {
                    FirstName                = firstName,
                    LastName                 = lastName,
                    EmailAddress             = email,
                    IdentityProvider         = IdentityProvider.Stockwinners,
                    IdentityProviderIssuedId = memberId.ToString()
                }, rememberUser: false);
            }

            ViewBag.ShowTemporaryPassword = true;

            return(View("RegistrationSuccess"));
        }
Ejemplo n.º 2
0
        public ActionResult Register(RegistrationModel model)
        {
            if (ModelState.IsValid)
            {
                MembershipCreateStatus createStatus;
                WebSite.Infrastructure.MembershipProvider membershipProvider = Membership.Provider as WebSite.Infrastructure.MembershipProvider;

                int memberId = membershipProvider.CreateStockwinnersMember(model.Email, model.Password, model.FirstName, model.LastName, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    Authentication.SetCurrentUser(new LoggedInUserIdentity()
                    {
                        FirstName                = model.FirstName,
                        LastName                 = model.LastName,
                        EmailAddress             = model.Email,
                        IdentityProvider         = IdentityProvider.Stockwinners,
                        IdentityProviderIssuedId = memberId.ToString()
                    }, rememberUser: false);

                    return(this.RedirectToAction("RegistrationSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Authenticates a Stockwinners member. Returns false if the provided login credentials are invalid.
        /// </summary>
        public static bool AuthenticateOrRedirectStockwinnersMember(string emailAddress, string password, string redirectUrl, bool rememberUser)
        {
            WebSite.Infrastructure.MembershipProvider memberProvider = Membership.Provider as WebSite.Infrastructure.MembershipProvider;

            // Lookup the Stockwinners member to locate first and last names
            StockwinnersMember member = memberProvider.GetStockwinnersMember(emailAddress, password);

            if (member != null)
            {
                Authentication.SetCurrentUser(new LoggedInUserIdentity()
                {
                    FirstName                = member.FirstName,
                    LastName                 = member.LastName,
                    EmailAddress             = member.EmailAddress,
                    IdentityProvider         = IdentityProvider.Stockwinners,
                    IdentityProviderIssuedId = member.MemberId.ToString()
                }, rememberUser);

                Authentication.Redirect(redirectUrl);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public ActionResult ResetPassword(string emailAddress)
        {
            ViewBag.InvalidEmail     = false;
            ViewBag.SuccessfulChange = false;
            WebSite.Infrastructure.MembershipProvider membershipProvider = Membership.Provider as WebSite.Infrastructure.MembershipProvider;
            string resetPassword = membershipProvider.ResetPassword(emailAddress, string.Empty);

            if (resetPassword == null)
            {
                ViewBag.InvalidEmail = true;
            }
            else
            {
                // Email the new password to the user
                _database.StockwinnersMembers.First(swMember => swMember.EmailAddress == emailAddress).SendPasswordResetEmail(resetPassword);

                ViewBag.SuccessfulChange = true;
            }

            return(this.View());
        }