protected void SaveButton_Click(object sender, EventArgs e)
        {
            int userId = Convert.ToInt32(UserIdHid.Value);

            string[] errors = Validate(userId);
            if (errors.Length == 0)
            {
                if (userId == 0)
                {
                    StreamingLiveLib.User existing = StreamingLiveLib.User.LoadByEmail(EmailText.Text);
                    if (existing == null)
                    {
                        StreamingLiveLib.User user = new StreamingLiveLib.User();
                        user.DisplayName = NameText.Text;
                        user.Email       = EmailText.Text;
                        user.Password    = StreamingLiveLib.User.HashPassword(PasswordText.Text);
                        user.Save();
                        userId = user.Id;
                    }
                    else
                    {
                        userId = existing.Id;
                    }
                    new StreamingLiveLib.Role()
                    {
                        SiteId = AppUser.Current.Site.Id, Name = RoleList.SelectedValue, UserId = userId
                    }.Save();
                }
                else if (RoleList.Enabled)
                {
                    StreamingLiveLib.Role role = StreamingLiveLib.Role.Load(userId, AppUser.Current.Site.Id);
                    role.Name = RoleList.SelectedValue;
                    role.Save();
                }

                Populate();
                OutputMessage("<b>Success:</b> Changes saved.", false, OutputLit);
            }
            else
            {
                OutputMessage("<b>Error:</b><ul><li>" + String.Join("</li><li>", errors) + "</li></ul>", true, OutputLit);
            }
        }
        public IActionResult OnPostRegister()
        {
            if (ModelState.IsValid)
            {
                string[] errors = Validate();
                if (errors.Length == 0)
                {
                    string webRoot = CachedData.Environment.WebRootPath;

                    StreamingLiveLib.Site s = new StreamingLiveLib.Site()
                    {
                        KeyName = KeyName.ToLower().Trim(), PrimaryColor = "#24b9ff", ContrastColor = "#ffffff", HeaderColor = "#24b9ff", HomePageUrl = "/", LogoUrl = "/data/master/logo.png", RegistrationDate = DateTime.UtcNow
                    };
                    s.Save();

                    StreamingLiveLib.User u = new StreamingLiveLib.User()
                    {
                        Email = Email.ToLower().Trim(), Password = StreamingLiveLib.User.HashPassword(Password.Trim()), DisplayName = "Admin"
                    };
                    u.ResetGuid = Guid.NewGuid().ToString();
                    u.Save();

                    StreamingLiveLib.Role r = new StreamingLiveLib.Role()
                    {
                        Name = "admin", SiteId = s.Id, UserId = u.Id
                    };
                    r.Save();


                    new StreamingLiveLib.Button()
                    {
                        SiteId = s.Id, Sort = 1, Text = "Resources", Url = "about:blank"
                    }.Save();
                    new StreamingLiveLib.Button()
                    {
                        SiteId = s.Id, Sort = 2, Text = "Give", Url = "about:blank"
                    }.Save();

                    new StreamingLiveLib.Tab()
                    {
                        SiteId = s.Id, Sort = 1, TabType = "chat", TabData = "", Icon = "far fa-comment", Text = "Chat", Url = ""
                    }.Save();
                    new StreamingLiveLib.Tab()
                    {
                        SiteId = s.Id, Sort = 2, TabType = "url", TabData = "", Icon = "fas fa-bible", Text = "Bible", Url = "https://www.bible.com/en-GB/bible/111/GEN.1.NIV"
                    }.Save();
                    new StreamingLiveLib.Tab()
                    {
                        SiteId = s.Id, Sort = 3, TabType = "prayer", TabData = "", Icon = "fas fa-praying-hands", Text = "Prayer", Url = ""
                    }.Save();

                    DateTime serviceTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 9 + 5, 0, 0).AddDays(1);
                    while (serviceTime.DayOfWeek != DayOfWeek.Sunday)
                    {
                        serviceTime = serviceTime.AddDays(1);
                    }
                    new StreamingLiveLib.Service()
                    {
                        SiteId = s.Id, ChatAfter = 15 * 60, ChatBefore = 15 * 60, Duration = 60 * 60, EarlyStart = 5 * 60, Provider = "youtube_watchparty", ProviderKey = "zFOfmAHFKNw", VideoUrl = "https://www.youtube.com/embed/zFOfmAHFKNw?autoplay=1&controls=0&showinfo=0&rel=0&modestbranding=1&disablekb=1", ServiceTime = serviceTime, TimezoneOffset = 300, Recurring = false
                    }.Save();


                    Utils.CopyS3(S3Client, "data/master/data.json", $"data/{s.KeyName}/data.json");
                    Utils.CopyS3(S3Client, "data/master/data.css", $"data/{s.KeyName}/data.css");

                    try
                    {
                        string body = "<a href=\"https://" + s.KeyName + ".streaminglive.church/\">https://" + s.KeyName + ".streaminglive.church/</a> - " + u.Email;
                        //StreamingLiveLib.Aws.EmailHelper.SendEmail(CachedData.SupportEmail, CachedData.SupportEmail, "New StreamingLive.church Registration", body);
                    }
                    catch { }



                    AppUser.Login(u);

                    var claims   = new[] { new Claim(ClaimTypes.Name, u.ResetGuid), new Claim(ClaimTypes.Role, "User") };
                    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
                    return(Redirect("/cp/"));
                }
                else
                {
                    OutputMessage = Utils.FormatMessage("<b>Error:</b><ul><li>" + String.Join("</li><li>", errors) + "</li></ul>", true);
                    return(Page());
                }
            }
            else
            {
                return(Page());
            }
        }