Exemplo n.º 1
0
        public ActionResult Register()
        {
            RegisterViewModel model   = new RegisterViewModel();
            UserService       service = new UserService();

            model.Locations = DemographyHelper.ConvertLocationsToDropdownList(service.GetAllLocations());
            model.Parties   = DemographyHelper.ConvertPartiesToDropdownList(service.GetAllParties());

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = AuthenticationManager.GetExternalLoginInfo();
                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ApplicationUser()
                {
                    Age        = model.Age,
                    Email      = model.Email,
                    Education  = model.Education,
                    LocationID = model.LocationID,
                    PartyID    = model.PartyID == 0 ? null : model.PartyID,
                    UserName   = model.UserName
                };
                IdentityResult result = UserManager.Create(user);
                if (result.Succeeded)
                {
                    result = UserManager.AddLogin(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        SignIn(user, isPersistent: false);

                        // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                        // Send an email with this link
                        // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // SendEmail(user.Email, callbackUrl, "Confirm your account", "Please confirm your account by clicking this link");

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            UserService service = new UserService();

            model.Locations = DemographyHelper.ConvertLocationsToDropdownList(service.GetAllLocations());
            model.Parties   = DemographyHelper.ConvertPartiesToDropdownList(service.GetAllParties());

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = AuthenticationManager.GetExternalLoginInfo();

            if (loginInfo == null)
            {
                return(RedirectToAction("Login"));
            }

            // Sign in the user with this external login provider if the user already has a login
            var user = UserManager.Find(loginInfo.Login);

            if (user != null)
            {
                if (user.IsDisabled)
                {
                    ViewBag.errorMessage = GlobalLocalization.Account_DisabledMessage;
                    return(View("Error"));
                }

                SignIn(user, isPersistent: false);
                return(RedirectToLocal(returnUrl));
            }
            else
            {
                // If the user does not have an account, then prompt the user to create an account
                ViewBag.ReturnUrl     = returnUrl;
                ViewBag.LoginProvider = loginInfo.Login.LoginProvider;

                UserService service = new UserService();

                ExternalLoginConfirmationViewModel model = new ExternalLoginConfirmationViewModel()
                {
                    Email     = loginInfo.Email,
                    Locations = DemographyHelper.ConvertLocationsToDropdownList(service.GetAllLocations()),
                    Parties   = DemographyHelper.ConvertPartiesToDropdownList(service.GetAllParties())
                };
                var nameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name");
                model.UserName = nameClaim.Value;


                return(View("ExternalLoginConfirmation", model));
            }
        }
Exemplo n.º 4
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    Age        = model.Age,
                    Email      = model.Email,
                    Education  = model.Education,
                    LocationID = model.LocationID,
                    PartyID    = model.PartyID == 0 ? null : model.PartyID,
                    UserName   = model.Email
                };

                ViewBag.Message = GlobalLocalization.Account_ConfirmEmail_EmailSent_Message;


                IdentityResult result = UserManager.Create(user, model.Password);
                if (result.Succeeded)
                {
                    //await SignInAsync( user, isPersistent: false );


                    SendEmailConfirmationToken(user.Id, GlobalLocalization.Account_ConfirmEmail_EmailSubject);


                    return(View("Info"));
                    //return RedirectToAction( "Index", "Home" );
                }
                else
                {
                    UserService service = new UserService();
                    model.Locations = DemographyHelper.ConvertLocationsToDropdownList(service.GetAllLocations());
                    model.Parties   = DemographyHelper.ConvertPartiesToDropdownList(service.GetAllParties());

                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }