Ejemplo n.º 1
0
        public async Task <ActionResult> Login(string userName, string password, string returnUrl)
        {
            ProjectManagerUser user = await UserManager.FindAsync(userName, password);

            if (user != null)
            {
                IAuthenticationManager authManager = HttpContext.GetOwinContext().Authentication;
                authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                authManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = true
                }, await user.GenerateUserIdentityAsync(UserManager));

                if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(Redirect(returnUrl));
                }
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(string userName, string email, string password, string confirmPassword)
        {
            ProjectManagerUser user = new ProjectManagerUser();

            user.UserName = userName;
            user.Email    = email;

            if (!password.Equals(confirmPassword))
            {
                ViewBag.ErrorName = "PasswordMismatch";
                return(View());
            }

            IdentityResult result = await UserManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                IAuthenticationManager authManager = HttpContext.GetOwinContext().Authentication;
                authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
                authManager.SignIn(new AuthenticationProperties()
                {
                    IsPersistent = false
                }, await user.GenerateUserIdentityAsync(UserManager));
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.ErrorName      = "RegisterFailed";
                ViewBag.RegisterErrors = new List <string>();

                foreach (string error in result.Errors)
                {
                    ViewBag.RegisterErrors.Add(error);
                }

                return(View());
            }
        }