Project

General

Profile

Bug #5556

Changing profile when e-mail not requiered

Added by Stijn Michels over 8 years ago. Updated over 8 years ago.

Status:
Bug resolved
Priority:
Normal
Assignee:
-
Category:
-
Target version:
Start date:
28/09/2012
Due date:
% Done:

90%

Estimated time:
Spent time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

E-mail is not required (in settings).
When changing the name or official code as administrator. The system asks me to enter an e-mail address.
The system doesn't care about the setting and requier an e-mailaddress.


Files

config.gif (34.8 KB) config.gif Yoselyn Castillo, 09/10/2012 18:41
profile.php (30 KB) profile.php Yoselyn Castillo, 19/10/2012 15:12
user_edit.php (16.5 KB) user_edit.php Yoselyn Castillo, 19/10/2012 15:12
profile.php (30.4 KB) profile.php Yoselyn Castillo, 22/10/2012 13:19
profile.php (30.3 KB) profile.php Yoselyn Castillo, 22/11/2012 16:41
user_add.php (13.7 KB) user_add.php Yoselyn Castillo, 06/12/2012 15:24

Associated revisions

Revision 13e4c5a8 (diff)
Added by Yoselyn Castillo over 8 years ago

Should fix bug when changing the email in the user's profile see #5556

Revision dce31c5d (diff)
Added by Yoselyn Castillo over 8 years ago

Fixing email required bug see #5556

Revision 16e1d7a0 (diff)
Added by Julio Montoya over 8 years ago

Fixing check_user_email() function see #5556

Revision e81d1aff (diff)
Added by Yoselyn Castillo over 8 years ago

Changing profile e-mail not required bug fixed see #5556

History

#1

Updated by Yoselyn Castillo over 8 years ago

  • Status changed from New to Assigned
  • Assignee set to Yoselyn Castillo
#2

Updated by Yoselyn Castillo over 8 years ago

I have tested and if the email is required or not, it always saves the email, email never remains empty without any message. Is that the correct behavior?

#3

Updated by Yoselyn Castillo over 8 years ago

  • File profile.php added
  • Assignee changed from Yoselyn Castillo to Julio Montoya

Here is the correction if it is allowed to save blank email.

#4

Updated by Julio Montoya over 8 years ago

  • Status changed from Assigned to Needs testing
  • Assignee deleted (Julio Montoya)
  • % Done changed from 0 to 50

The file was sent

#5

Updated by Stijn Michels over 8 years ago

When the global Chamilo settings say that e-mail is not required. In the profile update page the red asterix (*) should not be shown.
In version 1.9.2 it's still shown in the profile update page and it is required.
The correct behavior is:
required in global settings = required while updating profile
not required in global settings = not required and can be blank.

#6

Updated by Yoselyn Castillo over 8 years ago

  • Assignee set to Yoselyn Castillo

i am going to check again...

#7

Updated by Yoselyn Castillo over 8 years ago

In stable.chamilo.org it works fine for me
I have made email not required in configuration settings/user (see the config.gif attachment)
I went to profile.php and email field doesn't show the red asterisk and it can be saved as blank(see the profile.gif attachment).

#8

Updated by Stijn Michels over 8 years ago

This works fine in 1.9.2 indeed.

#9

Updated by Yoselyn Castillo over 8 years ago

  • Status changed from Needs testing to Bug resolved
  • % Done changed from 50 to 100
#10

Updated by Stijn Michels over 8 years ago

This problem is back in 1.9.4 nightly built 16/10 and also on the stable.chamilo.org.

#11

Updated by Yoselyn Castillo over 8 years ago

  • Status changed from Bug resolved to Assigned

Really the bug is different now. What i detect is:
if you want to change the name, the email is saved as blank though the email has value or not.
Reopening the task...

#12

Updated by Stijn Michels over 8 years ago

The email is saved as blank in while editing profile trough the social network (/main/auth/profile.php).

When using main/admin/user_edit.php*, the asterix is shown even if the email is not required.

In fact these are two related bugs.

#13

Updated by Yoselyn Castillo over 8 years ago

Ok, i had no tested in main/admin/user_edit.php, thanks.
Working...

#14

Updated by Yoselyn Castillo over 8 years ago

Upload these files. I will test github today in order to solve the problems with my commits :)
I have made some fixes.
In profile.php email and the other fields are saved correctly now
Fixed the problem with red asterisk in user_edit.php too

#15

Updated by Stijn Michels over 8 years ago

This seems to be fixed. Works fine for me.

#16

Updated by Julio Montoya over 8 years ago

  • Assignee changed from Julio Montoya to Yoselyn Castillo

I upload both files but if you removed the content of the function check_user_email() in profile.php you should removed all calls to that function.

#17

Updated by Yoselyn Castillo over 8 years ago

Sorry, it was a mistake about removing the content of check_user_email function. Upload this, or copy the content of function again:
function check_user_email($email) {
$user_id = api_get_user_id();
if ($user_id != strval(intval($user_id)) || empty($email)) { return false; }
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$email = Database::escape_string($email);
$sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND email='".$email."'";
$result = Database::query($sql_password);
return Database::num_rows($result) != 0;
}

Thanks

#18

Updated by Yoselyn Castillo over 8 years ago

  • File deleted (profile.gif)
#19

Updated by Yoselyn Castillo over 8 years ago

  • File deleted (profile.php)
#20

Updated by Julio Montoya over 8 years ago

  • Status changed from Assigned to Needs testing
  • Assignee deleted (Julio Montoya)

that makes sense :) file was sent

#21

Updated by Yoselyn Castillo over 8 years ago

  • Assignee set to Yoselyn Castillo
#22

Updated by Yoselyn Castillo over 8 years ago

As I see, it works already fine, if there is no other bug, we can close the task

#23

Updated by Stijn Michels over 8 years ago

Today (nightly build 2012-11-10) a learner tried to change the password.
Inserting the old and 2 times a new password.
The new password is not saved.
I logged in as administrator and changed the user details, setting a new password this worked.

Changing the password doesn't work in the profile... This is odd.

#24

Updated by Yoselyn Castillo over 8 years ago

I will verify right now

#25

Updated by Yoselyn Castillo over 8 years ago

  • Status changed from Needs testing to Assigned

I confirm that bug. It makes the verifications, but the pass is not saved, it keeps the old pass. Working...

#26

Updated by Yoselyn Castillo over 8 years ago

  • File profile.php added
  • Assignee changed from Yoselyn Castillo to Julio Montoya

line 596

#27

Updated by Julio Montoya over 8 years ago

  • Status changed from Assigned to Needs more info
  • Assignee changed from Julio Montoya to Yoselyn Castillo
  • % Done changed from 100 to 90

The file you are sending has all this changes not only the line 596.

Before fixing a bug remember to have the latest code from our repository.


# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- BASE
+++ LOCAL
@@ -12,6 +12,8 @@
  * Code
  */

+/*  Init section  */
+
 // Language files that should be included.
 $language_file = array('registration', 'messages', 'userInfo');
 $cidReset = true;
@@ -32,7 +34,7 @@
 $htmlHeadXtra[] = '<script src="../inc/lib/javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
 $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';

-$htmlHeadXtra[] = '<script>
+$htmlHeadXtra[] = '<script type="text/javascript">
 function confirmation(name) {
     if (confirm("'.get_lang('AreYouSureToDelete', '').' " + name + " ?")) {
             document.forms["profile"].submit();
@@ -92,17 +94,18 @@
 EOF;
 }

-//    Configuration file
+//    Configuration file
 require_once api_get_path(CONFIGURATION_PATH).'profile.conf.php';

 // Libraries
 require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';

+
 $tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');
 $table_user = Database :: get_main_table(TABLE_MAIN_USER);

-/*    Form    */
+/*    Form    */

 /*
  * Get initial values for all fields.
@@ -128,10 +131,10 @@
  * Otherwise, if a user has productions and presses ENTER to submit, he will
  * attempt to delete the first production in the list. */
 //if (is_profile_editable()) {
-//    $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"', array('style' => 'visibility:hidden;'));
+//    $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"', array('style' => 'visibility:hidden;'));
 //}

-//    SUBMIT (visible)
+//    SUBMIT (visible)
 /*if (is_profile_editable()) {
     $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
 } else {
@@ -147,11 +150,11 @@
 }

 if (api_is_western_name_order()) {
-    //    FIRST NAME and LAST NAME
+    //    FIRST NAME and LAST NAME
     $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
     $form->addElement('text', 'lastname',  get_lang('LastName'),  array('size' => 40));
 } else {
-    //    LAST NAME and FIRST NAME
+    //    LAST NAME and FIRST NAME
     $form->addElement('text', 'lastname',  get_lang('LastName'),  array('size' => 40));
     $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
 }
@@ -163,7 +166,7 @@
 $form->addRule('lastname' , get_lang('ThisFieldIsRequired'), 'required');
 $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');

-//    USERNAME
+//    USERNAME
 $form->addElement('text', 'username', get_lang('UserName'), array('maxlength' => USERNAME_MAX_LENGTH, 'size' => USERNAME_MAX_LENGTH));
 if (api_get_setting('profile', 'login') !== 'true') {
     $form->freeze('username');
@@ -174,7 +177,7 @@
 $form->addRule('username', get_lang('UsernameWrong'), 'username');
 $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);

-//    OFFICIAL CODE
+//    OFFICIAL CODE
 if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
     $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
     if (api_get_setting('profile', 'officialcode') !== 'true') {
@@ -187,7 +190,7 @@
     }
 }

-//    EMAIL
+//    EMAIL
 $form->addElement('email', 'email', get_lang('Email'), array('size' => 40));
 if (api_get_setting('profile', 'email') !== 'true') {
     $form->freeze('email');
@@ -208,11 +211,11 @@
     }
     $form->applyFilter('openid', 'trim');
     //if (api_get_setting('registration', 'openid') == 'true') {
-    //    $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required');
+    //    $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required');
     //}
 }

-//    PHONE
+//    PHONE
 $form->addElement('text', 'phone', get_lang('phone'), array('size' => 20));
 if (api_get_setting('profile', 'phone') !== 'true') {
     $form->freeze('phone');
@@ -224,7 +227,7 @@
 }
 $form->addRule('phone', get_lang('EmailWrong'), 'email');*/

-//    PICTURE
+//    PICTURE
 if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
     $form->addElement('file', 'picture', ($user_data['picture_uri'] != '' ? get_lang('UpdateImage') : get_lang('AddImage')));
     $form->add_progress_bar();
@@ -235,43 +238,43 @@
     $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
 }

-//    LANGUAGE
+//    LANGUAGE
 $form->addElement('select_language', 'language', get_lang('Language'));
 if (api_get_setting('profile', 'language') !== 'true') {
     $form->freeze('language');
 }

-//    EXTENDED PROFILE  this make the page very slow!
+//    EXTENDED PROFILE  this make the page very slow!
 if (api_get_setting('extended_profile') == 'true') {
     if (!isset($_GET['type']) || (isset($_GET['type']) && $_GET['type'] == 'extended')) {
         $width_extended_profile = 500;
         //$form->addElement('html', '<a href="javascript: void(0);" onclick="javascript: show_extend();"> show_extend_profile</a>');
         //$form->addElement('static', null, '<em>'.get_lang('OptionalTextFields').'</em>');
-        //    MY COMPETENCES
+        //    MY COMPETENCES
         $form->add_html_editor('competences', get_lang('MyCompetences'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130'));
-        //    MY DIPLOMAS
+        //    MY DIPLOMAS
         $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130'));
-        //    WHAT I AM ABLE TO TEACH
+        //    WHAT I AM ABLE TO TEACH
         $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130'));

-        //    MY PRODUCTIONS
+        //    MY PRODUCTIONS
         $form->addElement('file', 'production', get_lang('MyProductions'));
         if ($production_list = UserManager::build_production_list(api_get_user_id(), '', true)) {
             $form->addElement('static', 'productions_list', null, $production_list);
         }
-        //    MY PERSONAL OPEN AREA
+        //    MY PERSONAL OPEN AREA
         $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false, false, array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '350'));
         $form->applyFilter(array('competences', 'diplomas', 'teach', 'openarea'), 'stripslashes');
         $form->applyFilter(array('competences', 'diplomas', 'teach'), 'trim'); // openarea is untrimmed for maximum openness
     }
 }

-//    PASSWORD, if auth_source is platform
+//    PASSWORD, if auth_source is platform
 if (is_platform_authentication() && is_profile_editable() && api_get_setting('profile', 'password') == 'true') {
     $form->addElement('password', 'password0', array(get_lang('Pass'), get_lang('Enter2passToChange')), array('size' => 40));    
     $form->addElement('password', 'password1', get_lang('NewPass'), array('size' => 40));
     $form->addElement('password', 'password2', get_lang('Confirmation'), array('size' => 40));
-    //    user must enter identical password twice so we can prevent some user errors
+    //    user must enter identical password twice so we can prevent some user errors
     $form->addRule(array('password1', 'password2'), get_lang('PassTwo'), 'compare');
     if (CHECK_PASS_EASY_TO_FIND) {
         $form->addRule('password1', get_lang('CurrentPasswordEmptyOrIncorrect'), 'callback', 'api_check_password');
@@ -280,11 +283,11 @@

 // EXTRA FIELDS
 $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
-$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'profile', false, api_get_user_id());
+$return_params = UserManager::set_extra_fields_in_form($form, $extra_data, 'profile');
 $jquery_ready_content = $return_params['jquery_ready_content'];

 // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
-$htmlHeadXtra[] ='<script>
+$htmlHeadXtra[] ='<script type="text/javascript">
 $(document).ready(function(){
     '.$jquery_ready_content.'
 });
@@ -296,7 +299,7 @@
     $form->addElement('html', '</div>');
     $form->addElement('button', 'generate_api_key', get_lang('GenerateApiKey'), array('id' => 'id_generate_api_key', 'onclick' => 'generate_open_id_form()')); //generate_open_id_form()
 }
-//    SUBMIT
+//    SUBMIT
 if (is_profile_editable()) {
     $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
 } else {
@@ -306,7 +309,7 @@
 $user_data = array_merge($user_data, $extra_data);
 $form->setDefaults($user_data);

-/*        FUNCTIONS   */
+/*        FUNCTIONS   */

 /**
@@ -322,7 +325,7 @@
 /**
  * Can a user edit his/her profile?
  *
- * @return    boolean    Editability of the profile
+ * @return    boolean    Editability of the profile
  */
 function is_profile_editable() {
     return $GLOBALS['profileIsEditable'];
@@ -335,8 +338,8 @@
 /**
  * Upload a submitted user production.
  *
- * @param    $user_id    User id
- * @return    The filename of the new production or FALSE if the upload has failed
+ * @param    $user_id    User id
+ * @return    The filename of the new production or FALSE if the upload has failed
  */
 function upload_user_production($user_id) {
     $image_path = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
@@ -359,8 +362,8 @@

 /**
  * Check current user's current password
- * @param    char    password
- * @return    bool true o false
+ * @param    char    password
+ * @return    bool true o false
  * @uses Gets user ID from global variable
  */
 function check_user_password($password){
@@ -375,8 +378,8 @@
 }
 /**
  * Check current user's current password
- * @param    char    email
- * @return    bool true o false
+ * @param    char    email
+ * @return    bool true o false
  * @uses Gets user ID from global variable
  */
 function check_user_email($email) {
@@ -389,7 +392,7 @@
     return Database::num_rows($result) != 0;
 }

-/*        MAIN CODE */
+/*        MAIN CODE */
 $filtered_extension         = false;
 $update_success             = false;
 $upload_picture_success     = false;
@@ -419,7 +422,7 @@
 if ($form->validate()) {

     $wrong_current_password = false;
-//    $user_data = $form->exportValues();
+//    $user_data = $form->exportValues();
     $user_data = $form->getSubmitValues();

     // set password if a new one was provided
@@ -444,16 +447,16 @@
     }

+    $changeemail = '';

+    //If user is sending the email to be changed (input is available and is not freeze )
+    if (api_get_setting('registration', 'email') == 'true' &&  api_get_setting('profile', 'email') == 'true') {        

-    //If user sending the email to be changed (input available and not frozen )
-    if (api_get_setting('profile', 'email') == 'true') {        
         if ($allow_users_to_change_email_with_no_password) {            
             if (!check_user_email($user_data['email'])) {
                 $changeemail = $user_data['email'];
                 //$_SESSION['change_email'] = 'success';
             }  
-                     
         } else {
             //Normal behaviour
             if (!check_user_email($user_data['email']) && !empty($user_data['password0']) && !$wrong_current_password) {
@@ -578,10 +581,10 @@

     //change email
     if ($allow_users_to_change_email_with_no_password) {        
-        if (isset($changeemail) && in_array('email', $available_values_to_modify)) {
+        if (!empty($changeemail) && in_array('email', $available_values_to_modify)) {
             $sql .= " email = '".Database::escape_string($changeemail)."',";
         }
-        if (!empty($changeemail) && isset($password) && in_array('password', $available_values_to_modify)) {
+        if (isset($password) && in_array('password', $available_values_to_modify)) {
             $password = api_get_encrypted_password($password);
             $sql .= " password = '".Database::escape_string($password)."'";
         } else {            
@@ -590,13 +593,12 @@
         }        
     } else {
         //normal behaviour
-        if(empty($changeemail) && isset($password)) {
-            $sql .= " email = y@u.com";
-        }
         if (isset($changeemail) && !isset($password) && in_array('email', $available_values_to_modify)) {
             $sql .= " email = '".Database::escape_string($changeemail)."'";
         } elseif (isset($password) && isset($changeemail) && in_array('email', $available_values_to_modify) && in_array('password', $available_values_to_modify)) {            
+            if (!empty($changeemail)) {
             $sql .= " email = '".Database::escape_string($changeemail)."',";
+            }
             $password = api_get_encrypted_password($password);
             $sql .= " password = '".Database::escape_string($password)."'";
         } elseif (isset($password) && in_array('password', $available_values_to_modify)) {
@@ -607,18 +609,13 @@
             $sql = rtrim($sql, ',');
         }        
     }
-    if (api_get_setting('profile', 'officialcode') == 'true' && isset($user_data['official_code'])) {
-        $sql .= ", official_code = '".Database::escape_string($user_data['official_code'])."'";
-    }
-
     $sql .= " WHERE user_id  = '".api_get_user_id()."'";
     Database::query($sql);

     // User tag process
     //1. Deleting all user tags
-    $list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(UserManager::USER_FIELD_TYPE_TAG);
-    
+    $list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(USER_FIELD_TYPE_TAG);
     if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) {
         foreach ($list_extra_field_type_tag as $id) {
             UserManager::delete_user_tags(api_get_user_id(), $id);
@@ -626,11 +623,10 @@
     }

     //2. Update the extra fields and user tags if available
-    
     if (is_array($extras) && count($extras)> 0) {        
         foreach ($extras as $key => $value) {
             //3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
-            UserManager::update_extra_field_value(api_get_user_id(), $key, $value);
+            $myres = UserManager::update_extra_field_value(api_get_user_id(), $key, $value);
         }        
     }

@@ -644,7 +640,7 @@
 }

-/*          MAIN DISPLAY SECTION  */
+/*          MAIN DISPLAY SECTION  */
 // the header
 Display::display_header(get_lang('ModifyProfile'));

@@ -682,6 +678,7 @@
     if ($upload_production_success) {
         $message.='<br />'.get_lang('ProductionUploaded');
     }
+
     Display :: display_confirmation_message($message, false);
 }

@@ -726,6 +723,7 @@
 $show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false;

 if (api_get_setting('allow_social_tool') == 'true') {    
+    
\ No newline at end of file
     echo '<div class="row-fluid">';
         echo '<div class="span3">';
         echo SocialManager::show_social_menu('home', null, api_get_user_id(), false, $show_delete_account_button);


#28

Updated by Yoselyn Castillo over 8 years ago

yes you're right i was testing with an old file. Fixing...

#29

Updated by Yoselyn Castillo over 8 years ago

  • File profile.php profile.php added
  • Status changed from Needs more info to Assigned
  • Assignee changed from Yoselyn Castillo to Julio Montoya

Line 584

#30

Updated by Yoselyn Castillo over 8 years ago

  • File deleted (profile.php)
#31

Updated by Julio Montoya over 8 years ago

  • Status changed from Assigned to Needs testing
  • Assignee deleted (Julio Montoya)

great! fix was sent

#32

Updated by Stijn Michels over 8 years ago

changing profile works in nightly built 31 nov. Great!

#33

Updated by Stijn Michels over 8 years ago

Related to this bug... one file is forgotten.
/main/admin/user_add.php

Even the e-mail address is not required... in this page (also)... it doesn't care about the global setting and keeps asking for an e-mail address.
Go for it Yoselyn, I know this is peace of cake for you ;-)

#34

Updated by Julio Montoya over 8 years ago

  • Status changed from Needs testing to Assigned
  • Assignee set to Yoselyn Castillo
#35

Updated by Yoselyn Castillo over 8 years ago

yes, i will take it. checking...

#36

Updated by Yoselyn Castillo over 8 years ago

Fixed.

#37

Updated by Stijn Michels over 8 years ago

Indeed. Thanks Yoselyn. I think this #5556 is done, now.

#38

Updated by Julio Montoya over 8 years ago

  • Status changed from Assigned to Needs more info
  • Assignee deleted (Julio Montoya)

file was sent

#39

Updated by Yoselyn Castillo over 8 years ago

  • Status changed from Needs more info to Bug resolved

Fixed, if the e-mail address is not required in user_add.php page it doesn't ask for this field.

Also available in: Atom PDF