Esempio n. 1
0
        public JsonResult registrate(UsersVM model)
        {
            if (_authHandler.CreateUser(model) != 0)
            {
                return(Json(Url.Action("login", "authentication"), JsonRequestBehavior.AllowGet));
            }

            return(Json(string.Empty, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public IActionResult Register(User user)
        {
            bool SignedIn = false;

            Utilities.UserToView(this, ref SignedIn);

            if (SignedIn)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (!AuthenticationHandler.UserExists(user))
                {
                    AuthenticationHandler.CreateUser(user);
                    AuthenticationHandler.SignIn(HttpContext.Session, user);
                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("UserName", $"User with username {user.Username} already exists");
            }
            return(View(user));
        }