Esempio n. 1
0
        public async Task<ActionResult> Register([Bind(Include = "Email,Password,RepeatPassword")] RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = new AppUser
            {
                Email = model.Email,
                DateCreated = DateTime.Now,
                UserName = model.Email
            };

            var result = await userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await SignIn(user);
                return RedirectToAction("Index", "Notes");
            }

            foreach (var error in result.Errors)
            {
                ModelState.AddModelError("Email", error);
            }

            return View();
        }
Esempio n. 2
0
 private async Task SignIn(AppUser user)
 {
     var identity = await userManager.CreateIdentityAsync(
         user, DefaultAuthenticationTypes.ApplicationCookie);
     GetAuthenticationManager().SignIn(identity);
 }