Ejemplo n.º 1
0
        public async Task<ActionResult> Register(RegisterModel model)
        {
            if (model.Password != model.ConfirmPassword)
                ModelState.AddModelError("password", "Passwords did not match");

            if (!ModelState.IsValid)
            {
                return View();
            }

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

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

            if (result.Succeeded)
            {
                await SignIn(user);
                return Redirect(GetRedirectUrl(model.ReturnURL));
            }

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

            return View();
        }
Ejemplo n.º 2
0
 public ActionResult Register(string returnURL)
 {
     if (string.IsNullOrWhiteSpace(returnURL))
         returnURL = Request.UrlReferrer.LocalPath;
     var model = new RegisterModel() { ReturnURL = returnURL };
     return View(model);
 }