Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-30878 core_user_update_users user password is reset if not specified

Conflicts:

	user/lib.php
  • Loading branch information...
commit 2e91e1ae9d2ce75917bdad05180fe63b9dacd809 1 parent b1945c7
Jérôme Mouneyrac mouneyrac authored

Showing 1 changed file with 28 additions and 17 deletions. Show diff stats Hide diff stats

  1. +28 17 user/lib.php
45 user/lib.php
@@ -27,47 +27,60 @@
27 27
28 28 /**
29 29 * Creates a user
  30 + *
30 31 * @param object $user user to create
31 32 * @return int id of the newly created user
32 33 */
33 34 function user_create_user($user) {
34 35 global $DB;
35 36
36   -/// set the timecreate field to the current time
  37 + // set the timecreate field to the current time
37 38 if (!is_object($user)) {
38 39 $user = (object)$user;
39 40 }
40 41
41   - /// hash the password
42   - $user->password = hash_internal_user_password($user->password);
  42 + // save the password in a temp value for later
  43 + if (isset($user->password)) {
  44 + $userpassword = $user->password;
  45 + unset($user->password);
  46 + }
43 47
44 48 $user->timecreated = time();
45 49 $user->timemodified = $user->timecreated;
46 50
47   -/// insert the user into the database
  51 + // insert the user into the database
48 52 $newuserid = $DB->insert_record('user', $user);
49 53
50   -/// create USER context for this user
  54 + // trigger user_created event on the full database user row
  55 + $newuser = $DB->get_record('user', array('id' => $newuserid));
  56 + events_trigger('user_created', $newuser);
  57 +
  58 + // create USER context for this user
51 59 get_context_instance(CONTEXT_USER, $newuserid);
52 60
  61 + // update user password if necessary
  62 + if (isset($userpassword)) {
  63 + update_internal_user_password($newuser, $userpassword);
  64 + }
  65 +
53 66 return $newuserid;
54 67
55 68 }
56 69
57 70 /**
58 71 * Update a user with a user object (will compare against the ID)
59   - * @param object $user - the user to update
  72 + *
  73 + * @param object $user the user to update
60 74 */
61 75 function user_update_user($user) {
62 76 global $DB;
63 77
64   - /// set the timecreate field to the current time
  78 + // set the timecreate field to the current time
65 79 if (!is_object($user)) {
66 80 $user = (object)$user;
67 81 }
68   -
69   - //MDL-30878
70   - //unset password here, for updating later
  82 +
  83 + // unset password here, for updating later
71 84 if (isset($user->password)) {
72 85 $passwd = $user->password;
73 86 unset($user->password);
@@ -76,19 +89,17 @@ function user_update_user($user) {
76 89 $user->timemodified = time();
77 90 $DB->update_record('user', $user);
78 91
79   - /// trigger user_updated event on the full database user row
  92 + // trigger user_updated event on the full database user row
80 93 $updateduser = $DB->get_record('user', array('id' => $user->id));
  94 + events_trigger('user_updated', $updateduser);
81 95
82   - //MDL-30878
83   - //if password was set, then update its hash
84   - if (isset($passwd))
  96 + // if password was set, then update its hash
  97 + if (isset($passwd)) {
85 98 update_internal_user_password($updateduser, $passwd);
86   -
87   - events_trigger('user_updated', $updateduser);
  99 + }
88 100
89 101 }
90 102
91   -
92 103 /**
93 104 * Marks user deleted in internal user database and notifies the auth plugin.
94 105 * Also unenrols user from all roles and does other cleanup.

0 comments on commit 2e91e1a

Please sign in to comment.
Something went wrong with that request. Please try again.