function perform($edit = array())
 {
     $fields = array();
     if (validate_nonblank($edit['username'])) {
         $fields['username'] = $edit['username'];
     }
     if (validate_nonblank($edit['email'])) {
         $fields['email'] = $edit['email'];
     }
     if (count($fields) < 1) {
         error_exit("You must supply at least one of username or email address");
     }
     /* Now, try and find the user */
     $user = Person::load($fields);
     /* Now, we either have one or zero users.  Regardless, we'll present
      * the user with the same output; that prevents them from using this
      * to guess valid usernames.
      */
     if ($user) {
         /* Generate a password */
         $pass = generate_password();
         $user->set_password($pass);
         if (!$user->save()) {
             error_exit("Error setting password");
         }
         /* And fire off an email */
         $rc = send_mail($user, false, false, _person_mail_text('password_reset_subject', array('%site' => variable_get('app_name', 'Leaguerunner'))), _person_mail_text('password_reset_body', array('%fullname' => "{$user->firstname} {$user->lastname}", '%username' => $user->username, '%password' => $pass, '%site' => variable_get('app_name', 'Leaguerunner'))));
         if ($rc == false) {
             error_exit("System was unable to send email to that user.  Please contact system administrator.");
         }
     }
 }
Beispiel #2
0
 function check_input_errors($edit)
 {
     $errors = array();
     if (!validate_nonhtml($edit['name'])) {
         $errors['edit[name]'] = 'You must enter a valid team name';
     } else {
         if (!$this->team->validate_unique($edit['name'])) {
             $errors['edit[name]'] = 'You must enter a unique team name';
         }
     }
     if (!validate_nonhtml($edit['shirt_colour'])) {
         $errors['edit[shirt_colour]'] = 'Shirt colour cannot be left blank';
     }
     if (validate_nonblank($edit['website'])) {
         if (!validate_nonhtml($edit['website'])) {
             $errors['edit[website]'] = 'If you provide a website URL, it must be valid. Otherwise, leave the website field blank.';
         }
     }
     return $errors;
 }
Beispiel #3
0
/**
 * Validate a Canadian postalcode
 *
 * Code borrowed from the BSD-licensed PEAR package 'Validate', which is too
 * large and bloated to be used here.
 */
function validate_canadian_postalcode($postalcode, $prov)
{
    if (!validate_nonblank($postalcode)) {
        return false;
    }
    $letters = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
    switch (strtoupper($prov)) {
        case 'NF':
            // Newfoundland
        // Newfoundland
        case 'NEWFOUNDLAND':
        case 'NEWFOUNDLAND AND LABRADOR':
            $sRegExp = 'A';
            break;
        case 'NS':
            // Nova Scotia
        // Nova Scotia
        case 'NOVA SCOTIA':
            $sRegExp = 'B';
            break;
        case 'PE':
            // Prince Edward Island
        // Prince Edward Island
        case 'PRINCE EDWARD ISLAND':
            $sRegExp = 'C';
            break;
        case 'NB':
            // New Brunswick
        // New Brunswick
        case 'NEW BRUNSWICK':
            $sRegExp = 'E';
            break;
        case 'QC':
            // Quebec
        // Quebec
        case 'QUEBEC':
            $sRegExp = '[GHJ]';
            break;
        case 'ON':
            // Ontario
        // Ontario
        case 'ONTARIO':
            $sRegExp = '[KLMNP]';
            break;
        case 'MB':
            // Manitoba
        // Manitoba
        case 'MANITOBA':
            $sRegExp = 'R';
            break;
        case 'SK':
            // Saskatchewan
        // Saskatchewan
        case 'SASKATCHEWAN':
            $sRegExp = 'S';
            break;
        case 'AB':
            // Alberta
        // Alberta
        case 'ALBERTA':
            $sRegExp = 'T';
            break;
        case 'BC':
            // British Columbia
        // British Columbia
        case 'BRITISH COLUMBIA':
            $sRegExp = 'V';
            break;
        case 'NT':
            // Northwest Territories
        // Northwest Territories
        case 'NORTHWEST TERRITORIES':
        case 'NU':
            // Nunavut
        // Nunavut
        case 'NUNAVUT':
            $sRegExp = 'X';
            break;
        case 'YK':
            // Yukon Territory
        // Yukon Territory
        case 'YUKON':
            $sRegExp = 'Y';
            break;
        default:
            return false;
    }
    $sRegExp .= '[0-9][' . $letters . '][ \\t-]*[0-9][ ' . $letters . '][0-9]';
    $sRegExp = '/^' . $sRegExp . '$/';
    return (bool) preg_match($sRegExp, strtoupper($postalcode));
}
Beispiel #4
0
 function check_input_errors($edit = array())
 {
     global $lr_session;
     $errors = array();
     if ($lr_session->has_permission('person', 'edit', $this->person->user_id, 'name')) {
         if (!validate_name_input($edit['firstname']) || !validate_name_input($edit['lastname'])) {
             $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in first and last names";
         }
     }
     if ($lr_session->has_permission('person', 'edit', $this->person->user_id, 'username')) {
         if (!validate_name_input($edit['username'])) {
             $errors[] = "You can only use letters, numbers, spaces, and the characters - ' and . in usernames";
         }
         $user = Person::load(array('username' => $edit['username']));
         # TODO: BUG: need to check that $user->user_id != current id
         if ($user && !$lr_session->is_admin()) {
             $errors[] = "A user with that username already exists; please choose another";
         }
     }
     if (!validate_email_input($edit['email'])) {
         $errors[] = "You must supply a valid email address";
     }
     if (!validate_nonblank($edit['home_phone']) && !validate_nonblank($edit['work_phone']) && !validate_nonblank($edit['mobile_phone'])) {
         $errors[] = "You must supply at least one valid telephone number.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['home_phone']) && !validate_telephone_input($edit['home_phone'])) {
         $errors[] = "Home telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['work_phone']) && !validate_telephone_input($edit['work_phone'])) {
         $errors[] = "Work telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     if (validate_nonblank($edit['mobile_phone']) && !validate_telephone_input($edit['mobile_phone'])) {
         $errors[] = "Mobile telephone number is not valid.  Please supply area code, number and (if any) extension.";
     }
     $address_errors = validate_address($edit['addr_street'], $edit['addr_city'], $edit['addr_prov'], $edit['addr_postalcode'], $edit['addr_country']);
     if (count($address_errors) > 0) {
         $errors = array_merge($errors, $address_errors);
     }
     if (!preg_match("/^[mf]/i", $edit['gender'])) {
         $errors[] = "You must select either male or female for gender.";
     }
     if (!validate_yyyymmdd_input($edit['birthdate'])) {
         $errors[] = "You must provide a valid birthdate";
     }
     if (validate_nonblank($edit['height'])) {
         if (!$lr_session->is_admin() && ($edit['height'] < 36 || $edit['height'] > 84)) {
             $errors[] = "Please enter a reasonable and valid value for your height.";
         }
     }
     if ($edit['skill_level'] < 1 || $edit['skill_level'] > 10) {
         $errors[] = "You must select a skill level between 1 and 10. You entered " . $edit['skill_level'];
     }
     $current = localtime(time(), 1);
     $this_year = $current['tm_year'] + 1900;
     if ($edit['year_started'] > $this_year) {
         $errors[] = "Year started must be before current year.";
     }
     if ($edit['year_started'] < 1986) {
         $errors[] = "Year started must be after 1986.  For the number of people who started playing before then, I don't think it matters if you're listed as having played 17 years or 20, you're still old. :)";
     }
     $birth_year = substr($edit['birthdate'], 0, 4);
     $yearDiff = $edit['year_started'] - $birth_year;
     if ($yearDiff < 8) {
         $errors[] = "You can't have started playing when you were {$yearDiff} years old!  Please correct your birthdate, or your starting year";
     }
     return $errors;
 }
 function validate()
 {
     $errors = "";
     if (!validate_nonblank($this->payment_type)) {
         $errors .= "\n<li>Payment Type must be nonblank";
     }
     if (!validate_nonblank($this->payment_method)) {
         $errors .= "\n<li>Payment Method must be nonblank";
     }
     if (!preg_match("/^\\d+(?:\\.\\d\\d)?\$/", $this->payment_amount)) {
         $errors .= "\n<li>Amount must be nonblank and a valid dollar amount";
     }
     if (!validate_nonblank($this->date_paid)) {
         $errors .= "\n<li>Payment date must be nonblank";
     }
     list($yyyy, $mm, $dd) = preg_split("/[\\/-]/", $this->date_paid);
     if (!validate_date_input($yyyy, $mm, $dd)) {
         $errors .= "\n<li>Payment date must be valid";
     }
     return $errors;
 }
Beispiel #6
0
 function isDataInvalid($edit)
 {
     $errors = "";
     if (!validate_number($edit['num'])) {
         $errors .= "<li>Number of field must be provided";
     }
     $rating = field_rating_values();
     if (!array_key_exists($edit['rating'], $rating)) {
         $errors .= "<li>Rating must be provided";
     }
     if ($edit['parent_fid'] > 0) {
         if (!validate_number($edit['parent_fid'])) {
             $errors .= "<li>Parent must be a valid value";
             return $errors;
         }
         if ($edit['parent_fid'] == $this->field->fid) {
             $errors .= "<li>Field cannot be a parent of itself!";
             return $errors;
         }
         return false;
     }
     if (!validate_nonhtml($edit['name'])) {
         $errors .= "<li>Name cannot be left blank, and cannot contain HTML";
     }
     if (!validate_nonhtml($edit['code'])) {
         $errors .= "<li>Code cannot be left blank and cannot contain HTML";
     }
     if (!validate_nonhtml($edit['region'])) {
         $errors .= "<li>Region cannot be left blank and cannot contain HTML";
     }
     if (validate_nonblank($edit['location_url'])) {
         if (!validate_nonhtml($edit['location_url'])) {
             $errors .= "<li>If you provide a location URL, it must be valid.";
         }
     }
     if (validate_nonblank($edit['layout_url'])) {
         if (!validate_nonhtml($edit['layout_url'])) {
             $errors .= "<li>If you provide a site layout URL, it must be valid.";
         }
     }
     if (strlen($errors) > 0) {
         return $errors;
     } else {
         return false;
     }
 }
Beispiel #7
0
 function check_input_errors($edit = array())
 {
     $errors = array();
     if (!validate_number($edit['num'])) {
         $errors[] = "Number of field must be provided";
     }
     $rating = field_rating_values();
     if (!array_key_exists($edit['rating'], $rating)) {
         $errors[] = "Rating must be provided";
     }
     if ($edit['parent_fid'] > 0) {
         if (!validate_number($edit['parent_fid'])) {
             $errors[] = "Parent must be a valid value";
         }
         return $errors;
     }
     if (!validate_nonhtml($edit['name'])) {
         $errors[] = "Name cannot be left blank, and cannot contain HTML";
     }
     if (!validate_nonhtml($edit['code'])) {
         $errors[] = "Code cannot be left blank and cannot contain HTML";
     }
     if (!validate_nonhtml($edit['region'])) {
         $errors[] = "Region cannot be left blank and cannot contain HTML";
     }
     if (validate_nonblank($edit['location_url'])) {
         if (!validate_nonhtml($edit['location_url'])) {
             $errors[] = "If you provide a location URL, it must be valid.";
         }
     }
     if (validate_nonblank($edit['layout_url'])) {
         if (!validate_nonhtml($edit['layout_url'])) {
             $errors[] = "If you provide a site layout URL, it must be valid.";
         }
     }
     return $error;
 }