示例#1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(hfConfirmDelete.Value))
            {
                hfConfirmDelete.Value = "DELETE";
                btnDelete.CssClass    = "btn btn-block btn-danger";
                btnDelete.Text        = "Confirm Delete";
            }
            else
            {
                RockContext rockContext = new RockContext();

                int pinEntityId     = EntityTypeCache.Get("Rock.Security.Authentication.PINAuthentication").Id;
                var userLoginEntity = new EntityTypeService(rockContext).Get(pinEntityId);
                var userAuthorized  = userLoginEntity.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);
                if (!userAuthorized)
                {
                    mdEditPin.Hide();
                    return;
                }

                int pinId = hfPinID.ValueAsInt();
                UserLoginService userLoginService = new UserLoginService(rockContext);
                UserLogin        pin = userLoginService.Get(pinId);
                userLoginService.Delete(pin);
                rockContext.SaveChanges();
                mdEditPin.Hide();
                DisplayPINs();
            }
        }
示例#2
0
        private void DisplayPINs()
        {
            int pinEntityId = EntityTypeCache.Get("Rock.Security.Authentication.PINAuthentication").Id;

            RockContext rockContext     = new RockContext();
            var         userLoginEntity = new EntityTypeService(rockContext).Get(pinEntityId);
            var         userAuthorized  = userLoginEntity.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);

            if (userAuthorized)
            {
                lbAdd.Visible = true;
            }

            var pins = new UserLoginService(rockContext).GetByPersonId(Person.Id).Where(ul => ul.EntityTypeId == pinEntityId).ToList();

            phPin.Controls.Clear();
            foreach (var pin in pins)
            {
                var rowPanel = new Panel();
                rowPanel.CssClass = "row rollover-container";
                phPin.Controls.Add(rowPanel);

                var firstPanel = new Panel();
                firstPanel.CssClass = "col-xs-1";
                rowPanel.Controls.Add(firstPanel);

                var secondPanel = new Panel();
                secondPanel.CssClass = "col-xs-10";
                rowPanel.Controls.Add(secondPanel);

                pin.LoadAttributes();
                List <string> purpose = new List <string>();
                if (pin.GetAttributeValue("PINPurpose") != null)
                {
                    var purposeIds = pin.GetAttributeValue("PINPurpose")
                                     .Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)
                                     .ToList();
                    if (purposeIds.Any())
                    {
                        foreach (var purposeId in purposeIds)
                        {
                            var dvPurpose = DefinedValueCache.Get(purposeId.AsInteger());
                            if (dvPurpose != null)
                            {
                                purpose.Add(dvPurpose.Value);
                            }
                        }
                    }
                    else
                    {
                        purpose.Add("[No Purpose]");
                    }
                }
                else
                {
                    purpose.Add("[No Purpose]");
                }

                RockLiteral rockLiteral = new RockLiteral();
                rockLiteral.Label = pin.UserName;
                rockLiteral.Text  = string.Join(", ", purpose);
                secondPanel.Controls.Add(rockLiteral);

                var thirdPanel = new Panel();
                thirdPanel.CssClass = "col-xs-1 rollover-item";
                rowPanel.Controls.Add(thirdPanel);

                if (userAuthorized)
                {
                    LinkButton lbEdit = new LinkButton();
                    lbEdit.ID     = pin.Guid.ToString();
                    lbEdit.Text   = "<i class='fa fa-pencil'></i>";
                    lbEdit.Click += (s, ee) => EditPin(pin.Id, rockContext);
                    thirdPanel.Controls.Add(lbEdit);
                }
            }
        }
示例#3
0
        protected void mdEditPin_SaveClick(object sender, EventArgs e)
        {
            RockContext rockContext = new RockContext();

            int pinEntityId     = EntityTypeCache.Get("Rock.Security.Authentication.PINAuthentication").Id;
            var userLoginEntity = new EntityTypeService(rockContext).Get(pinEntityId);
            var userAuthorized  = userLoginEntity.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);

            if (!userAuthorized)
            {
                mdEditPin.Hide();
                return;
            }

            int pinId = hfPinID.ValueAsInt();
            UserLoginService userLoginService = new UserLoginService(rockContext);
            UserLogin        pin = userLoginService.Get(pinId);

            var number = tbPin.Text.AsDouble();

            if (number == 0)
            {
                nbError.Visible = true;
                nbError.Text    = "Error: Requested PIN could not be converted to number.";
                return;
            }

            var minimumPinLength = GetAttributeValue("MinimumPINLength").AsInteger();

            if (number.ToString().Length < minimumPinLength)
            {
                nbError.Visible = true;
                nbError.Text    = string.Format("Error: Requested PIN must be {0} digits or greater.", minimumPinLength);
                return;
            }

            //Check to see if this PIN already exists in the system
            if (pin == null || number.ToString() != pin.UserName)
            {
                if (userLoginService.GetByUserName(number.ToString()) != null)
                {
                    nbError.Visible = true;
                    nbError.Text    = "This PIN has already been taken.";
                    return;
                }
            }


            if (pin != null)
            {
                //Check to see if we are accidentally overwriting someones username
                if (pin.EntityTypeId != pinEntityId)
                {
                    LogException(new Exception("Atempted edit on non-PIN in PIN manager"));
                    return;
                }
            }
            else
            {
                pin              = new UserLogin();
                pin.Id           = pinId;
                pin.IsConfirmed  = true;
                pin.PersonId     = Person.Id;
                pin.EntityTypeId = pinEntityId;
                userLoginService.Add(pin);
            }

            if (number.ToString() != pin.UserName)
            {
                pin.UserName = tbPin.Text;
                rockContext.SaveChanges();
            }
            pin.LoadAttributes();
            pin.SetAttributeValue("PINPurpose", string.Join("|", cblPurpose.SelectedValues));
            pin.SaveAttributeValues();
            mdEditPin.Hide();

            DisplayPINs();
        }