Beispiel #1
0
        public ActionResult Register(RegisterViewModel model)
        {
            var errorMsg = string.Empty;

            if (ModelState.IsValid)
            {
                var isRegistered = AuthServiceClient.RegisterUser(
                    username: model.Username,
                    email: model.Email,
                    password: model.Password,
                    errorMessage: out errorMsg);

                if (isRegistered)
                {
                    // Set the login cookie as well
                    var identity = new ClaimsIdentity(
                        new[] { new Claim(ClaimTypes.Name, model.Username), },
                        DefaultAuthenticationTypes.ApplicationCookie,
                        ClaimTypes.Name, ClaimTypes.Role);

                    Authentication.SignIn(new AuthenticationProperties {
                        IsPersistent = false
                    }, identity);

                    return(RedirectToAction("Index", "Home"));
                }
            }

            AddErrors(new IdentityResult(new string[] { errorMsg }));
            return(View(model));
        }