1919 */
2020class UsersApiResourceUser extends ApiResource
2121{
22+ /**
23+ * Array of fields to be unset
24+ *
25+ * @var array
26+ * @since 2.0.1
27+ */
28+ private $ fieldsToSanitize = array ('password ' , 'password_clear ' , 'otpKey ' , 'otep ' );
29+
2230 /**
2331 * Function to create and edit user record.
2432 *
@@ -33,17 +41,22 @@ public function post()
3341 $ formData = $ app ->input ->getArray ();
3442 $ userIdentifier = $ app ->input ->get ('id ' , 0 , 'string ' );
3543
44+ if (isset ($ formData ['fields ' ]))
45+ {
46+ $ formData ['com_fields ' ] = $ formData ['fields ' ];
47+ unset($ formData ['fields ' ]);
48+ }
49+
3650 // Get current logged in user.
3751 $ me = $ this ->plugin ->get ('user ' );
52+ $ iAmSuperAdmin = $ me ->authorise ('core.create ' );
3853
3954 if (!empty ($ userIdentifier ))
4055 {
4156 $ user = $ this ->retriveUser ($ userIdentifier );
4257
4358 if (!empty ($ user ->id ))
4459 {
45- $ iAmSuperAdmin = $ me ->authorise ('core.admin ' );
46-
4760 // Check if regular user is trying to update his/her own profile OR if user is superadmin
4861 if ($ me ->id == $ user ->id || $ iAmSuperAdmin )
4962 {
@@ -81,6 +94,13 @@ public function post()
8194 // Check if $userIdentifier is not set - POST / CREATE user case
8295 else
8396 {
97+ if (!$ iAmSuperAdmin )
98+ {
99+ ApiError::raiseError (400 , JText::_ ('JERROR_ALERTNOAUTHOR ' ));
100+
101+ return ;
102+ }
103+
84104 // Validate required fields
85105 if ($ formData ['username ' ] == '' || $ formData ['name ' ] == '' || $ formData ['email ' ] == '' )
86106 {
@@ -109,24 +129,21 @@ public function post()
109129 /**
110130 * Funtion to remove sensitive user info fields like password
111131 *
112- * @param Object $user The user object.
113- * @param Array $fields Array of fields to be unset
132+ * @param Object &$user The user object.
114133 *
115134 * @return object|void $user
116135 *
117136 * @since 2.0.1
118137 */
119- protected function sanitizeUserFields ($ user, $ fields = array ( ' password ' , ' password_clear ' , ' otpKey ' , ' otep ' ) )
138+ protected function sanitizeUserFields (& $ user )
120139 {
121- foreach ($ fields as $ f )
140+ foreach ($ this -> fieldsToSanitize as $ f )
122141 {
123142 if (isset ($ user ->{$ f }))
124143 {
125144 unset($ user ->{$ f });
126145 }
127146 }
128-
129- return $ user ;
130147 }
131148
132149 /**
@@ -167,7 +184,7 @@ public function get()
167184 }
168185 }
169186
170- $ user = $ this ->sanitizeUserFields ($ user );
187+ $ this ->sanitizeUserFields ($ user );
171188
172189 $ this ->plugin ->setResponse ($ user );
173190 }
@@ -328,7 +345,7 @@ private function retriveUser($userIdentifier)
328345
329346 // Flag to differentiate the column value
330347 $ app = JFactory::getApplication ();
331- $ xIdentifier = $ app ->input ->server ->get ('HTTP_X_IDENTIFIER ' , '' , 'string ' );
348+ $ xIdentifier = $ app ->input ->server ->get ('HTTP_X_IDENTIFIER ' , '' , 'WORD ' );
332349
333350 switch ($ xIdentifier )
334351 {
0 commit comments