public IActionResult Complete(RegisterModel model)
        {
            //prevent start wizard if already passed
            if (!bool.Parse(configuration["FirstRun"]))
                return View("Error", ALREADY_PASSED_MESSAGE);

            //redirect to first step if user came this url directly
            if (SystemController.dataBaseConfig == null)
                return RedirectToAction("Index");

            dynamic json = ReadConfig();
            json.FirstRun = false;
            WriteConfig(json);
            configuration.Reload();

            SystemController.Start(SystemController.configuration, SystemController.services);

            return RedirectToAction("Index", "Home");
        }
Ejemplo n.º 2
0
        public async Task<IActionResult> Register(RegisterModel model)
        {
            if (!SystemController.webServerRules.AllowRegistrationOfNewUsers)
                return View("Error", "Registration of new users is prohibited. Please contact administrator.");

            if (db == null)
                return View("Error", NO_DB_ERROR);

            if (ModelState.IsValid)
            {
                User user = db.GetUser(model.Name);
                if (user == null)
                {
                    user = new User()
                    {
                        Name = model.Name,
                        Email = model.Email,
                        Password = model.Password,
                    };

                    db.AddUser(user);

                    await Authenticate(user);

                    return RedirectToAction("Index", "Home");
                }

                ModelState.AddModelError("", "User already exists");
            }
            return View(model);
        }
        public async Task<IActionResult> UserProfile(RegisterModel model)
        {
            //prevent start wizard if already passed
            if (!bool.Parse(configuration["FirstRun"]))
                return View("Error", ALREADY_PASSED_MESSAGE);

            //redirect to first step if user came this url directly
            if (SystemController.dataBaseConfig == null)
                return RedirectToAction("Index");

            IUsersRepository db = SystemController.usersDb;

            if (ModelState.IsValid)
            {
                User user = db.GetUser(model.Name);
                if (user == null)
                {
                    user = new User()
                    {
                        Name = model.Name,
                        Email = model.Email,
                        Password = model.Password,
                    };

                    user.SetClaims(Users.User.GetAllClaims());

                    db.AddUser(user);

                    await Authenticate(user);

                    return RedirectToAction("Complete");
                }

                ModelState.AddModelError("", "User already exists");
            }
            return View(model);
        }