Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegistrationViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user   = model.ToMessageType();
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    LoggedInUserBinder.BindUser(Session, user.UserName, user.LoginCredential.EncryptedPassword);
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            User user = await UserManager.FindAsync(model.UserName, model.Password);

            if (user != null)
            {
                LoggedInUserBinder.BindUser(Session, user.UserName, user.LoginCredential.EncryptedPassword);
                await SignInAsync(user, false);

                return(RedirectToLocal(returnUrl));
            }
            else
            {
                ModelState.AddModelError("", "Invalid username or password.");
                return(View(model));
            }
        }