Ejemplo n.º 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!User.IsInRole("Admin"))
            {
                return(RedirectToAction("Login"));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.Password == model.PasswordCheck)
            {
                var hasher = new PasswordHasher <Account>();

                Account tempAccount = new Account(0, model.Username, model.Rockstars, model.IsAdmin, model.Password);

                string hashedPW = hasher.HashPassword(tempAccount, model.Password);

                tempAccount.Password = hashedPW;
                APIHelper.InitializeClient();
                AccountOperations.Create(tempAccount);

                return(RedirectToAction("Index", "Home"));
            }
            ModelState.AddModelError(nameof(model.Username), "Passwords do not match");

            return(View(model));
        }