Beispiel #1
0
        public ActionResult SystemStatus()
        {
            using (var db = ApplicationDbContext.Create())
            {
                if (!User.Identity.IsAuthenticated)
                {
                    throw new HttpException(403, "Forbidden");
                }

                var thisUser = db.Users.Where(x => x.UserName == User.Identity.Name)
                               .Include(x => x.Organizations)
                               .FirstOrDefault();

                if (!thisUser.IsAdministrator)
                {
                    throw new HttpException(403, "Forbidden");
                }
            }

            var checker = new SystemStatusChecker();
            var model   = checker.GetSystemStatus();

            return(View(model));
        }
Beispiel #2
0
        public ActionResult FirstRun()
        {
            var model = new FirstRunViewModel();

            var checker = new SystemStatusChecker();

            model.SystemStatus = checker.GetSystemStatus();

            // See if there are no connection strings.
            if (WebConfigurationManager.ConnectionStrings.Count == 0)
            {
                model.HasNoConnectionStrings = true;
            }

            // See if the DefaultConnection is empty.
            var defaultConnectionString = WebConfigurationManager.ConnectionStrings["DefaultConnection"];

            if (defaultConnectionString == null)
            {
                model.HasNoConnectionStrings = true;
            }

            return(View(model));
        }
Beispiel #3
0
        public async Task <ActionResult> FirstRun(FirstRunViewModel model)
        {
            // Don't allow this to be run if it has already been run successfully.
            string isConfiguredPath = HttpContext.Server.MapPath(SetupController.IsConfiguredMarkerPath);

            if (System.IO.File.Exists(isConfiguredPath))
            {
                throw new HttpException(404, "Not found");
            }

            var checker = new SystemStatusChecker();

            using (var db = ApplicationDbContext.Create())
            {
                try
                {
                    // Create the database if needed.
                    if (!db.Database.Exists())
                    {
                        db.Database.Create();
                    }
                }
                catch (Exception ex)
                {
                    model.Message      = ex.Message;
                    model.SystemStatus = checker.GetSystemStatus();
                    return(View(model));
                }

                try
                {
                    // Set the site-wide settings.
                    // Boo lookup instead of add-or-update.
                    var settingsRow = db.Settings.Where(x => x.Name == AdminController.SiteSettingsName).FirstOrDefault();
                    if (settingsRow == null)
                    {
                        settingsRow      = new Setting();
                        settingsRow.Name = AdminController.SiteSettingsName;
                        db.Settings.Add(settingsRow);
                    }

                    var settings = new SiteSettings();
                    settings.SiteName = model.SiteName;

                    settingsRow.Value = JsonConvert.SerializeObject(settings);

                    // Create the organization, if it does not already exist.
                    var org = db.Organizations.Where(x => x.Name == model.OrganizationName).FirstOrDefault();
                    if (org == null)
                    {
                        string host = Request.Headers["Host"];
                        org = new Organization()
                        {
                            Id       = Guid.NewGuid(),
                            Name     = model.OrganizationName,
                            AgencyID = model.AgencyId,
                            Hostname = host
                        };

                        db.Organizations.Add(org);
                    }

                    // Create the user.
                    var userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>();
                    var user        = await UserController.CreateUser(model.UserName, model.Password, model.FirstName, model.LastName,
                                                                      true,
                                                                      org,
                                                                      userManager,
                                                                      ModelState,
                                                                      db);

                    if (user == null)
                    {
                        model.Message      = "The user could not be created. Please try again.";
                        model.SystemStatus = checker.GetSystemStatus();
                        return(View(model));
                    }

                    db.SaveChanges();

                    // Indicate that setup has been run.
                    System.IO.File.WriteAllText(isConfiguredPath, DateTime.UtcNow.ToString());

                    return(RedirectToAction("Index", "Admin"));
                }
                catch (Exception ex)
                {
                    model.Message      = ex.Message;
                    model.SystemStatus = checker.GetSystemStatus();
                    return(View(model));
                }
            }
        }