Пример #1
0
        public IActionResult OnPostSignIn()
        {
            if (ModelState.IsValid)
            {
                StreamingLiveLib.User user = StreamingLiveLib.User.Login(Email, Password);

                if (user == null)
                {
                    ErrorMessage = "<div class=\"alert alert-warning\" role=\"alert\">Invalid email address / password combination.</div>";
                }
                else
                {
                    user.ResetGuid = Guid.NewGuid().ToString();
                    user.Save();
                    AppUser.Login(user);

                    var claims   = new[] { new Claim(ClaimTypes.Name, user.ResetGuid), new Claim(ClaimTypes.Role, "User") };
                    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
                    HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));

                    //***This doesn't seem like the right way to get the return url;
                    if (ReturnUrl == null || ReturnUrl == "")
                    {
                        ReturnUrl = "/cp/";
                    }
                    return(Redirect(ReturnUrl));
                }
            }
            return(this.Page());
        }
Пример #2
0
        protected void UserRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            StreamingLiveLib.User user     = (StreamingLiveLib.User)e.Item.DataItem;
            LinkButton            EditLink = (LinkButton)e.Item.FindControl("EditLink");

            EditLink.CommandArgument = user.Id.ToString();
        }
Пример #3
0
        private string[] Validate()
        {
            List <string> errors = new List <string>();

            if (NameText.Text.Trim() == "")
            {
                errors.Add("Name cannot be blank");
            }
            if (System.Text.RegularExpressions.Regex.Match(NameText.Text, "[A-Za-z0-9\\-_ \\.\\']{1,99}").Value != NameText.Text)
            {
                errors.Add("Invalid characters in name.");
            }
            if (!IsValidEmail(EmailText.Text))
            {
                errors.Add("Invalid email address.");
            }
            if (PasswordText.Text != "" && PasswordText.Text.Trim().Length < 6)
            {
                errors.Add("Password must be at least 6 characters.");
            }
            if (PasswordText.Text != PasswordConfirm.Text)
            {
                errors.Add("Passwords do not match.");
            }
            if (errors.Count == 0)
            {
                StreamingLiveLib.User existing = StreamingLiveLib.User.LoadByEmail(EmailText.Text);
                if (existing != null && existing.Id != AppUser.Current.UserData.Id)
                {
                    errors.Add("There is already an account registered with this email address.");
                }
            }
            return(errors.ToArray());
        }
Пример #4
0
 //not used.  Just keeping for reference
 public static StreamingLiveLib.User Map(this StreamingLiveCore.Pages.IndexModel model)
 {
     StreamingLiveLib.User result = new StreamingLiveLib.User()
     {
         Email    = model.Email,
         Password = model.Password,
     };
     return(result);
 }
Пример #5
0
 private void LoginGuid()
 {
     StreamingLiveLib.User user = StreamingLiveLib.User.LoadByResetGuid(Request["guid"]);
     if (user == null)
     {
         OutputLit.Text = "<div class=\"alert alert-warning\" role=\"alert\">Invalid token.  Please login or reset password again.</div>";
     }
     else
     {
         AppUser.Login(user);
         FormsAuthentication.RedirectFromLoginPage(user.Email, false);
     }
 }
 public void OnPostReset()
 {
     StreamingLiveLib.User user = StreamingLiveLib.User.LoadByEmail(Email);
     if (user == null)
     {
         OutputMessage = Utils.FormatMessage("Invalid email address.", true);
     }
     else
     {
         string guid = user.SetResetGuid();
         string body = "<p>Please click the <a href=\"/cp/login?guid=" + guid + "&ReturnUrl=%2fcp%2f\">here</a> to reset your StreamingLive.church password.</p>";
         StreamingLiveLib.Aws.EmailHelper.SendEmail(CachedData.SupportEmail, user.Email, "StreamingLive.church Password Reset Request", body);
         OutputMessage = Utils.FormatMessage("Password reset instructions have been sent to " + user.Email, false);
     }
 }
 protected void ResetButton_Click(object sender, EventArgs e)
 {
     StreamingLiveLib.User user = StreamingLiveLib.User.LoadByEmail(EmailText.Text);
     if (user == null)
     {
         OutputLit.Text = "<div class=\"alert alert-warning\" role=\"alert\">Invalid email address.</div>";
     }
     else
     {
         string guid = user.SetResetGuid();
         string body = "<p>Please click the <a href=\"" + CachedData.BaseUrl.Replace("old.", "") + "/cp/login.aspx?guid=" + guid + "&ReturnUrl=%2fcp%2f\">here</a> to reset your StreamingLive.church password.</p>";
         StreamingLiveLib.Aws.EmailHelper.SendEmail(CachedData.SupportEmail, user.Email, "StreamingLive.church Password Reset Request", body);
         OutputLit.Text = "<div class=\"alert alert-success\" role=\"alert\">Password reset instructions have been sent to " + user.Email + "</div>";
     }
 }
Пример #8
0
        protected void SigninButton_Click(object sender, EventArgs e)
        {
            StreamingLiveLib.User user = StreamingLiveLib.User.Login(EmailText.Text, PasswordText.Text);

            if (user == null)
            {
                OutputLit.Text = "<div class=\"alert alert-warning\" role=\"alert\">Invalid email address / password combination.</div>";
            }
            else
            {
                user.ResetGuid = Guid.NewGuid().ToString();
                user.Save();
                AppUser.Login(user);
                FormsAuthentication.RedirectFromLoginPage(user.ResetGuid, false);
            }
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        public static AppUser Login(StreamingLiveLib.User u)
        {
            StreamingLiveLib.Sites sites = StreamingLiveLib.Sites.LoadByUserId(u.Id);
            if (sites.Count == 0)
            {
                return(null);
            }
            StreamingLiveLib.Roles roles = StreamingLiveLib.Roles.LoadByUserId(u.Id);
            StreamingLiveLib.Role  role  = roles.GetBySiteId(sites[0].Id);
            if (role == null)
            {
                return(null);
            }
            AppUser user = new AppUser {
                UserData = u, Sites = sites, Role = role, Roles = roles, IsSiteAdmin = roles.GetByName("siteadmin").Count > 0
            };

            AppUser.Current = user;
            return(user);
        }
Пример #11
0
        private void ShowEditUser(int userId)
        {
            EditHolder.Visible = true;
            StreamingLiveLib.User user = (userId == 0) ? new StreamingLiveLib.User() : StreamingLiveLib.User.Load(userId);

            NameLit.Visible   = false;
            NameText.Visible  = false;
            EmailLit.Visible  = false;
            EmailText.Visible = false;

            if (userId == 0)
            {
                PasswordHolder.Visible = true;
                NameText.Visible       = true;
                EmailText.Visible      = true;
            }
            else
            {
                PasswordHolder.Visible = false;
                NameLit.Visible        = true;
                EmailLit.Visible       = true;
                NameLit.Text           = "<div>" + user.DisplayName + "</div>";
                EmailLit.Text          = "<div>" + user.Email + "</div>";
                StreamingLiveLib.Role role = StreamingLiveLib.Role.Load(userId, AppUser.Current.Site.Id);
                try
                {
                    RoleList.SelectedValue = role.Name;
                }
                catch { };
            }


            DeleteHolder.Visible = (userId != 0 && userId != AppUser.Current.UserData.Id);

            RoleList.Enabled = true;
            if (userId == AppUser.Current.UserData.Id)
            {
                RoleList.Enabled = false;
            }
            UserIdHid.Value = userId.ToString();
        }
Пример #12
0
        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());
            }
        }