Exemplo n.º 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index");

            if (!ModelState.IsValid)
                return View(model);

            // create new user
            var user = new User() {
                Email = model.Email,
                Name = model.Name,
                TwitterName = model.TwitterScreenname,
                FacebookUserName = model.FacebookUsername
            };
            user.SetPassword(model.Password);
            user.ExternalReferences.Add(new UserReference() { ProviderId = model.ProviderId, Reference = model.ProviderReference });

            // save user
            this.RavenSession().Store(user);
            this.RavenSession().SaveChanges();
            FormsAuthentication.SetAuthCookie(user.Id, true);

            this.AddInformation("Je registratie is voltooid.");
            this.AddCallToAction("Je kan nu je profiel aanvullen, als je dat wilt. Je kan dit ook later doen.", Url.Action("Index", new { id = user.Id }));

            return RedirectToAction("Index", "Main");
        }
Exemplo n.º 2
0
        public ActionResult Register()
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("Index");

            var info = TempData["ExternalAuthenticationInfo"] as ExternalAuthenticationInfo;

            RegisterViewModel model;
            if (info != null) {
                TempData["ExternalAuthenticationInfo"] = info;
                model = new RegisterViewModel() {
                    Email = info.Email,
                    Name = info.Name,
                    ProviderId = info.ProviderId,
                    ProviderName = GetProviderName(info.ProviderId),
                    ProviderReference = info.Id,
                    TwitterScreenname = info.ProviderId == "twitter" ? info.Username : null,
                    FacebookUsername = info.ProviderId == "facebook" ? info.Username : null,
                };
            }
            else {
                model = new RegisterViewModel();
            }

            return View(model);
        }