Exemplo n.º 1
0
 public ApplicantAddedLogEntry(Applicant newApplicant)
 {
     this.ApplicantId = newApplicant.Identity;
     if (HttpContext.Current != null)
     {
         ActingIPAddress = SupportFunctions.GetMostLikelyRemoteIPAddress();
     }
 }
Exemplo n.º 2
0
 public PersonAddedLogEntry(Participation participation, Person actingPerson)
 {
     DateTime        = System.DateTime.UtcNow;
     ParticipationId = participation.Identity;
     ActingPersonId  = actingPerson.Identity;
     if (HttpContext.Current != null)
     {
         ActingIPAddress = SupportFunctions.GetMostLikelyRemoteIPAddress();
     }
 }
Exemplo n.º 3
0
        public static AjaxInputCallResult SetPersonEditorData(int personId, string field, string newValue)
        {
            if (newValue == null || field == null)
            {
                throw new ArgumentNullException();
            }

            AuthenticationData authData = GetAuthenticationDataAndCulture();
            bool self = false;

            // Are we modifying ourselves?

            if (personId == 0)   // request self record
            {
                self     = true; // may make use of this later
                personId = authData.CurrentUser.Identity;
            }

            // Preliminary input validation

            if (string.IsNullOrEmpty(newValue))
            {
                if (field != "TwitterId") // These fields may be set to empty; default is disallow
                {
                    return(new AjaxInputCallResult
                    {
                        Success = false,
                        ObjectIdentity = personId,
                        DisplayMessage = Resources.Global.Global_FieldCannotBeEmpty,
                        FailReason = AjaxInputCallResult.ErrorInvalidFormat,
                        NewValue = GetPersonValue(personId, field)
                    });
                }
            }

            // Verify authority to see and change personal data

            Person affectedPerson = Person.FromIdentity(personId);

            if (!self)
            {
                if (!authData.Authority.CanSeePerson(affectedPerson) ||
                    !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, affectedPerson.Geography,
                                                             AccessAspect.PersonalData)))
                {
                    throw new UnauthorizedAccessException();
                }
            }

            string oldValue;
            string displayMessage = string.Empty;

            while (newValue.Contains("  "))
            {
                newValue = newValue.Trim().Replace("  ", " ");  // double, triple, quadruple spaces reduced to one
            }

            switch (field)
            {
            case "Name":
                oldValue            = affectedPerson.Name;
                affectedPerson.Name = newValue;
                break;

            case "Mail":
                oldValue            = affectedPerson.Mail;
                affectedPerson.Mail = newValue;
                break;

            case "Phone":
                oldValue             = affectedPerson.Phone;
                affectedPerson.Phone = newValue;
                if (!Regex.IsMatch(newValue, @"^[0-9 \(\)\-\+]+$"))
                {
                    // using characters not typically seen in a phone number? Warn
                    displayMessage = Resources.Global.Master_EditPersonWarning_Phone;
                }
                break;

            case "TwitterId":
                if (newValue.StartsWith("@"))
                {
                    newValue = newValue.Substring(1);
                }
                oldValue = affectedPerson.TwitterId;
                affectedPerson.TwitterId = newValue;
                break;

            default:
                throw new ArgumentException("Unrecognized field in /Automation/SwarmFunctions.SetPersonEditorData");
            }

            SwarmopsLogEntry logEntry = SwarmopsLog.CreateEntry(affectedPerson, new PersonalDataChangedLogEntry
            {
                ActingPersonId   = authData.CurrentUser.PersonId,
                AffectedPersonId = affectedPerson.PersonId,
                Field            = field,
                IpAddress        = SupportFunctions.GetMostLikelyRemoteIPAddress(),
                OldValue         = oldValue,
                NewValue         = newValue
            });

            if (!self)
            {
                logEntry.CreateAffectedObject(authData.CurrentUser);
            }

            return(new AjaxInputCallResult
            {
                ObjectIdentity = personId,
                Success = true,
                NewValue = newValue,
                DisplayMessage = displayMessage
            });
        }