From 0e1f9e51847165a3a8425c30acbd1099cfcb4b75 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 10 Aug 2015 11:00:39 -0500 Subject: [PATCH 1/5] Create tpl for reset password mail - refs BT#9897 #TMI --- main/inc/lib/login.lib.php | 19 +++++++++++++------ main/template/default/mail/reset_password.tpl | 4 ++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 main/template/default/mail/reset_password.tpl diff --git a/main/inc/lib/login.lib.php b/main/inc/lib/login.lib.php index 7bf69f1e1c..57d3ec7310 100755 --- a/main/inc/lib/login.lib.php +++ b/main/inc/lib/login.lib.php @@ -206,14 +206,21 @@ class Login Database::getManager()->flush(); $url = api_get_path(WEB_CODE_PATH).'auth/reset.php?token='.$uniqueId; + + $mailTemplate = new Template(null, false, false, false, false, false); + $mailTemplate->assign('complete_user_name', $user->getCompleteName()); + $mailTemplate->assign('link', $url); + + $mailLayout = $mailTemplate->get_template('mail/reset_password.tpl'); + + $mailSubject = get_lang('ResetPasswordInstructions'); + $mailBody = $mailTemplate->fetch($mailLayout); + api_mail_html( - '', + $user->getCompleteName(), $user->getEmail(), - get_lang('ResetPasswordInstructions'), - sprintf( - get_lang('ResetPasswordCommentWithUrl'), - $url - ) + $mailSubject, + $mailBody ); Display::addFlash(Display::return_message(get_lang('CheckYourEmailAndFollowInstructions'))); //} diff --git a/main/template/default/mail/reset_password.tpl b/main/template/default/mail/reset_password.tpl new file mode 100644 index 0000000000..0db1c5ba54 --- /dev/null +++ b/main/template/default/mail/reset_password.tpl @@ -0,0 +1,4 @@ +

{{ 'Dear' }} {{ complete_user_name }}

+

+ {{ 'ResetPasswordCommentWithUrl'|get_lang|format(link) }} +

From d1e4412031afeb53a03ea62d7a98f2520ab5826b Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 10 Aug 2015 12:32:00 -0500 Subject: [PATCH 2/5] Minor - Code conventions - refs BT#10139 #TMI --- main/admin/course_add.php | 10 +++++++++- main/admin/course_edit.php | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 05a9538c1e..73671c2f2c 100755 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -45,7 +45,15 @@ $form->applyFilter('title', 'html_filter'); $form->applyFilter('title', 'trim'); // Code -$form->addText('visual_code', array(get_lang('CourseCode'), get_lang('OnlyLettersAndNumbers')) , false, array('maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE)); +$form->addText( + 'visual_code', + array( + get_lang('CourseCode'), + get_lang('OnlyLettersAndNumbers') + ), + false, + array('maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE) +); $form->applyFilter('visual_code', 'api_strtoupper'); $form->applyFilter('visual_code', 'html_filter'); diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 325c8a0275..118424ad55 100755 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -108,7 +108,15 @@ $element = $form->addElement('text', 'real_code', array(get_lang('CourseCode'), $element->freeze(); // Visual code -$form->addText('visual_code', array(get_lang('VisualCode'), get_lang('OnlyLettersAndNumbers'), get_lang('ThisValueIsUsedInTheCourseURL')), true, array('class' => 'span4')); +$form->addText( + 'visual_code', + array( + get_lang('VisualCode'), + get_lang('OnlyLettersAndNumbers'), + get_lang('ThisValueIsUsedInTheCourseURL') + ), + true +); $form->applyFilter('visual_code', 'strtoupper'); $form->applyFilter('visual_code', 'html_filter'); From 69422fa712e400a5b656d5d21875e21d2236927a Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 10 Aug 2015 12:39:53 -0500 Subject: [PATCH 3/5] Add pattern to validate only letters and numbers on course code - refs BT#10139 --- main/admin/course_add.php | 6 +++++- main/admin/course_edit.php | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/main/admin/course_add.php b/main/admin/course_add.php index 73671c2f2c..e3ab664440 100755 --- a/main/admin/course_add.php +++ b/main/admin/course_add.php @@ -52,7 +52,11 @@ $form->addText( get_lang('OnlyLettersAndNumbers') ), false, - array('maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE) + [ + 'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE, + 'pattern' => '[a-zA-Z0-9]+', + 'title' => get_lang('OnlyLettersAndNumbers') + ] ); $form->applyFilter('visual_code', 'api_strtoupper'); diff --git a/main/admin/course_edit.php b/main/admin/course_edit.php index 118424ad55..fa9036125e 100755 --- a/main/admin/course_edit.php +++ b/main/admin/course_edit.php @@ -115,7 +115,12 @@ $form->addText( get_lang('OnlyLettersAndNumbers'), get_lang('ThisValueIsUsedInTheCourseURL') ), - true + true, + [ + 'maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE, + 'pattern' => '[a-zA-Z0-9]+', + 'title' => get_lang('OnlyLettersAndNumbers') + ] ); $form->applyFilter('visual_code', 'strtoupper'); From b1786914ed9746442a635ec6708c3436df02ed8d Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 10 Aug 2015 15:42:24 -0500 Subject: [PATCH 4/5] Create new extra fields letters and alphanumeric with spaces - refs BT#10139 #TMI --- main/inc/lib/extra_field.lib.php | 83 +++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 4ede414601..edcbdf8d42 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -63,6 +63,8 @@ class ExtraField extends Model const FIELD_TYPE_VIDEO_URL = 19; const FIELD_TYPE_LETTERS_ONLY = 20; const FIELD_TYPE_ALPHANUMERIC = 21; + const FIELD_TYPE_LETTERS_SPACE = 22; + const FIELD_TYPE_ALPHANUMERIC_SPACE = 23; public $type = 'user'; public $pageName; @@ -339,6 +341,12 @@ class ExtraField extends Model $types[self::FIELD_TYPE_VIDEO_URL] = get_lang('FieldTypeVideoUrl'); $types[self::FIELD_TYPE_LETTERS_ONLY] = get_lang('FieldTypeOnlyLetters'); $types[self::FIELD_TYPE_ALPHANUMERIC] = get_lang('FieldTypeAlphanumeric'); + $types[self::FIELD_TYPE_LETTERS_SPACE] = get_lang( + 'FieldTypeLettersSpace' + ); + $types[self::FIELD_TYPE_ALPHANUMERIC_SPACE] = get_lang( + 'FieldTypeNoPunctuation' + ); switch ($handler) { case 'course': @@ -1450,7 +1458,10 @@ EOF; $form->addElement( 'text', 'extra_' . $field_details['variable'], - $field_details['display_text'], + [ + $field_details['display_text'], + get_lang('OnlyLetters') + ], [ 'pattern' => '[a-zA-Z]+', 'title' => get_lang('OnlyLetters') @@ -1476,7 +1487,10 @@ EOF; $form->addElement( 'text', 'extra_' . $field_details['variable'], - $field_details['display_text'], + [ + $field_details['display_text'], + get_lang('OnlyLettersAndNumbers') + ], [ 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers') @@ -1503,6 +1517,71 @@ EOF; } } break; + case ExtraField::FIELD_TYPE_LETTERS_SPACE: + $form->addElement( + 'text', + 'extra_' . $field_details['variable'], + [ + $field_details['display_text'], + get_lang('OnlyLettersAndSpace') + ], + [ + 'pattern' => '[a-zA-Z\s]+', + 'title' => get_lang('OnlyLetters') + ] + ); + $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes'); + $form->applyFilter('extra_' . $field_details['variable'], 'trim'); + $form->addRule( + 'extra_' . $field_details['variable'], + get_lang('OnlyLettersAndSpace'), + 'regex', + '/^[a-zA-Z\s]+$/' + ); + + if (!$admin_permissions) { + if ($field_details['visible'] == 0) { + $form->freeze( + 'extra_' . $field_details['variable'] + ); + } + } + break; + case ExtraField::FIELD_TYPE_ALPHANUMERIC_SPACE: + $form->addElement( + 'text', + 'extra_' . $field_details['variable'], + [ + $field_details['display_text'], + get_lang('OnlyLettersAndNumbersAndSpaces') + ], + [ + 'pattern' => '[a-zA-Z0-9ñÑ\s]+', + 'title' => get_lang('OnlyLettersAndNumbersAndSpaces') + ] + ); + $form->applyFilter( + 'extra_' . $field_details['variable'], + 'stripslashes' + ); + $form->applyFilter( + 'extra_' . $field_details['variable'], + 'trim' + ); + $form->addRule( + 'extra_' . $field_details['variable'], + get_lang('OnlyLettersAndNumbers'), + 'regex', + '/^[a-zA-Z0-9ñÑ\s]+$/' + ); + if (!$admin_permissions) { + if ($field_details['visible'] == 0) { + $form->freeze( + 'extra_' . $field_details['variable'] + ); + } + } + break; } } } From bb444460b403d6cff1f0e0848087100143a047b7 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 10 Aug 2015 16:10:09 -0500 Subject: [PATCH 5/5] Create new methods for new inputs text with patterns - refs BT#10139 --- main/inc/lib/extra_field.lib.php | 88 ++------ .../lib/formvalidator/FormValidator.class.php | 188 ++++++++++++++++++ 2 files changed, 200 insertions(+), 76 deletions(-) diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index edcbdf8d42..4091fda4cb 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -1455,25 +1455,11 @@ EOF; ); break; case ExtraField::FIELD_TYPE_LETTERS_ONLY: - $form->addElement( - 'text', - 'extra_' . $field_details['variable'], - [ - $field_details['display_text'], - get_lang('OnlyLetters') - ], - [ - 'pattern' => '[a-zA-Z]+', - 'title' => get_lang('OnlyLetters') - ] + $form->addLettersOnly( + "extra_{$field_details['variable']}", + $field_details['display_text'] ); $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes'); - $form->applyFilter('extra_' . $field_details['variable'], 'trim'); - $form->addRule( - 'extra_' . $field_details['variable'], - get_lang('OnlyLetters'), - 'lettersonly' - ); if (!$admin_permissions) { if ($field_details['visible'] == 0) { @@ -1484,31 +1470,14 @@ EOF; } break; case ExtraField::FIELD_TYPE_ALPHANUMERIC: - $form->addElement( - 'text', - 'extra_' . $field_details['variable'], - [ - $field_details['display_text'], - get_lang('OnlyLettersAndNumbers') - ], - [ - 'pattern' => '[a-zA-Z0-9]+', - 'title' => get_lang('OnlyLettersAndNumbers') - ] + $form->addAlphanumeric( + "extra_{$field_details['variable']}", + $field_details['display_text'] ); $form->applyFilter( 'extra_' . $field_details['variable'], 'stripslashes' ); - $form->applyFilter( - 'extra_' . $field_details['variable'], - 'trim' - ); - $form->addRule( - 'extra_' . $field_details['variable'], - get_lang('OnlyLettersAndNumbers'), - 'alphanumeric' - ); if (!$admin_permissions) { if ($field_details['visible'] == 0) { $form->freeze( @@ -1518,26 +1487,11 @@ EOF; } break; case ExtraField::FIELD_TYPE_LETTERS_SPACE: - $form->addElement( - 'text', - 'extra_' . $field_details['variable'], - [ - $field_details['display_text'], - get_lang('OnlyLettersAndSpace') - ], - [ - 'pattern' => '[a-zA-Z\s]+', - 'title' => get_lang('OnlyLetters') - ] + $form->addLettersAndSpaces( + "extra_{$field_details['variable']}", + $field_details['display_text'] ); $form->applyFilter('extra_' . $field_details['variable'], 'stripslashes'); - $form->applyFilter('extra_' . $field_details['variable'], 'trim'); - $form->addRule( - 'extra_' . $field_details['variable'], - get_lang('OnlyLettersAndSpace'), - 'regex', - '/^[a-zA-Z\s]+$/' - ); if (!$admin_permissions) { if ($field_details['visible'] == 0) { @@ -1548,32 +1502,14 @@ EOF; } break; case ExtraField::FIELD_TYPE_ALPHANUMERIC_SPACE: - $form->addElement( - 'text', - 'extra_' . $field_details['variable'], - [ - $field_details['display_text'], - get_lang('OnlyLettersAndNumbersAndSpaces') - ], - [ - 'pattern' => '[a-zA-Z0-9ñÑ\s]+', - 'title' => get_lang('OnlyLettersAndNumbersAndSpaces') - ] + $form->addAlphanumericAndSpaces( + "extra_{$field_details['variable']}", + $field_details['display_text'] ); $form->applyFilter( 'extra_' . $field_details['variable'], 'stripslashes' ); - $form->applyFilter( - 'extra_' . $field_details['variable'], - 'trim' - ); - $form->addRule( - 'extra_' . $field_details['variable'], - get_lang('OnlyLettersAndNumbers'), - 'regex', - '/^[a-zA-Z0-9ñÑ\s]+$/' - ); if (!$admin_permissions) { if ($field_details['visible'] == 0) { $form->freeze( diff --git a/main/inc/lib/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index a3ea7d4cf5..5d03ff86e1 100755 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -1032,6 +1032,194 @@ EOT; } } + /** + * Adds a text field for letters to the form. + * A trim-filter is attached to the field. + * @param string $name The element name + * @param string $label The label for the form-element + * @param bool $required Optional. Is the form-element required (default=true) + * @param array $attributes Optional. List of attributes for the form-element + */ + public function addLettersOnly( + $name, + $label, + $required = false, + $attributes = [] + ) + { + $attributes = array_merge( + $attributes, + [ + 'pattern' => '[a-zA-ZñÑ]+', + 'title' => get_lang('OnlyLetters') + ] + ); + + $this->addElement( + 'text', + $name, + [ + $label, + get_lang('OnlyLetters') + ], + $attributes + ); + + $this->applyFilter($name, 'trim'); + + if ($required) { + $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); + } + + $this->addRule( + $name, + get_lang('OnlyLetters'), + 'regex', + '/^[a-zA-ZñÑ]+$/' + ); + } + + /** + * Adds a text field for alphanumeric characters to the form. + * A trim-filter is attached to the field. + * @param string $name The element name + * @param string $label The label for the form-element + * @param bool $required Optional. Is the form-element required (default=true) + * @param array $attributes Optional. List of attributes for the form-element + */ + public function addAlphanumeric( + $name, + $label, + $required = false, + $attributes = [] + ) + { + $attributes = array_merge( + $attributes, + [ + 'pattern' => '[a-zA-Z0-9ñÑ]+', + 'title' => get_lang('OnlyLettersAndNumbers') + ] + ); + + $this->addElement( + 'text', + $name, + [ + $label, + get_lang('OnlyLettersAndNumbers') + ], + $attributes + ); + + $this->applyFilter($name, 'trim'); + + if ($required) { + $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); + } + + $this->addRule( + $name, + get_lang('OnlyLettersAndNumbers'), + 'regex', + '/^[a-zA-Z0-9ÑÑ]+$/' + ); + } + + /** + * Adds a text field for letters and spaces to the form. + * A trim-filter is attached to the field. + * @param string $name The element name + * @param string $label The label for the form-element + * @param bool $required Optional. Is the form-element required (default=true) + * @param array $attributes Optional. List of attributes for the form-element + */ + public function addLettersAndSpaces( + $name, + $label, + $required = false, + $attributes = [] + ) + { + $attributes = array_merge( + $attributes, + [ + 'pattern' => '[a-zA-ZñÑ\s]+', + 'title' => get_lang('OnlyLettersAndSpace') + ] + ); + + $this->addElement( + 'text', + $name, + [ + $label, + get_lang('OnlyLettersAndSpace') + ], + $attributes + ); + + $this->applyFilter($name, 'trim'); + + if ($required) { + $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); + } + + $this->addRule( + $name, + get_lang('OnlyLettersAndSpace'), + 'regex', + '/^[a-zA-ZñÑ\s]+$/' + ); + } + + /** + * Adds a text field for alphanumeric and spaces characters to the form. + * A trim-filter is attached to the field. + * @param string $name The element name + * @param string $label The label for the form-element + * @param bool $required Optional. Is the form-element required (default=true) + * @param array $attributes Optional. List of attributes for the form-element + */ + public function addAlphanumericAndSpaces( + $name, + $label, + $required = false, + $attributes = [] + ) + { + $attributes = array_merge( + $attributes, + [ + 'pattern' => '[a-zA-Z0-9ñÑ\s]+', + 'title' => get_lang('OnlyLettersAndNumbersAndSpaces') + ] + ); + + $this->addElement( + 'text', + $name, + [ + $label, + get_lang('OnlyLettersAndNumbersAndSpaces') + ], + $attributes + ); + + $this->applyFilter($name, 'trim'); + + if ($required) { + $this->addRule($name, get_lang('ThisFieldIsRequired'), 'required'); + } + + $this->addRule( + $name, + get_lang('OnlyLettersAndNumbersAndSpaces'), + 'regex', + '/^[a-zA-Z0-9ñÑ\s]+$/' + ); + } + } /**