コード例 #1
0
        public async Task <ActionResult> Register(string username,
                                                  string password,
                                                  string email)
        {
            //Setup new user
            var user = new IdentityUser
            {
                UserName = username,
                Email    = email
            };
            //Register user in db
            var result = await userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                //Create a identity
                var identity = await userManager.CreateIdentityAsync(user,
                                                                     DefaultAuthenticationTypes.ApplicationCookie);

                //Create new claim
                identity.AddClaim(new Claim("Email", user.Email));

                var authorisationManager =
                    HttpContext.GetOwinContext().Authentication;
                //Sign in
                authorisationManager.SignIn(identity);
                var Acc = new AccountViewModel()
                {
                    UserName = user.UserName,
                    Email    = user.Email
                };
                Crud.CreateAccount(Acc.ToEntity());
            }
            return(RedirectToAction("Index", "Album"));
        }