Esempio n. 1
0
        public async void RegisterTest()
        {
            var form = new RegisterViewModel
            {
                Email = "*****@*****.**",
                Password = "******",
                ConfirmPassword = "******"
            };
            await _controller.Register(form);

            var loggedUser = _manager.FindByEmail("*****@*****.**");
            Assert.IsNotNull(loggedUser);
        }
Esempio n. 2
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View();
            }

            var user = new User
            {
                Email = model.Email,
                UserName = model.Email
            };

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

            if (result.Succeeded)
            {
                await SignInAsync(user, false);
                return RedirectToAction("index", "home");
            }

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

            return View();
        }