1212use FeatherBB \Core \Error ;
1313use FeatherBB \Core \Url ;
1414use FeatherBB \Core \Utils ;
15+ use FeatherBB \Core \Database as DB ;
1516use FeatherBB \Model \Delete ;
1617
1718class Profile
@@ -47,7 +48,7 @@ public function display($req, $res, $args)
4748
4849 return $ this ->model ->update_mod_forums ($ args ['id ' ]);
4950 } elseif (Input::post ('ban ' )) {
50- if (User::get ()-> g_id != ForumEnv:: get ( ' FEATHER_ADMIN ' ) && (!User::can ( ' mod.is_mod ' ) || !User::can ('mod.ban_users ' ))) {
51+ if (! User::isAdmin () && (!User::isAdminMod ( ) || !User::can ('mod.ban_users ' ))) {
5152 throw new Error (__ ('No permission ' ), 403 );
5253 }
5354
@@ -74,7 +75,7 @@ public function display($req, $res, $args)
7475
7576 if (User::get ()->id != $ args ['id ' ] && // If we aren't the user (i.e. editing your own profile)
7677 (!User::isAdminMod () || // and we are not an admin or mod
77- (User::get ()-> g_id != ForumEnv:: get ( ' FEATHER_ADMIN ' ) && // or we aren't an admin and ...
78+ (! User::isAdmin ( ) && // or we aren't an admin and ...
7879 (!User::can ('mod.edit_users ' ) || // mods aren't allowed to edit users
7980 $ info ['group_id ' ] == ForumEnv::get ('FEATHER_ADMIN ' ) || // or the user is an admin
8081 $ info ['is_moderator ' ])))) { // or the user is another mod
@@ -201,7 +202,7 @@ public function display($req, $res, $args)
201202
202203 } elseif ($ args ['section ' ] == 'admin ' ) {
203204
204- if (!User::isAdminMod () || (User::can ( ' mod.is_mod ' ) && !User::can ('mod.ban_users ' ))) {
205+ if (!User::isAdminMod () || (User::isAdminMod ( ) && !User::can ('mod.ban_users ' ))) {
205206 throw new Error (__ ('Bad request ' ), 404 );
206207 }
207208
@@ -239,30 +240,21 @@ public function action($req, $res, $args)
239240 }
240241 }
241242
243+ // Make sure user exists
244+ if (!DB ::for_table ('users ' )->find_one ($ args ['id ' ])) {
245+ throw new Error (__ ('Bad request ' ), 404 );
246+ }
247+
242248 if ($ args ['action ' ] == 'change_pass ' ) {
243249 // Make sure we are allowed to change this user's password
244250 if (User::get ()->id != $ args ['id ' ]) {
245251 $ args ['id ' ] = Container::get ('hooks ' )->fire ('controller.profile.change_pass_key_not_id ' , $ args ['id ' ]);
246252
247253 if (!User::isAdminMod ()) { // A regular user trying to change another user's password?
248254 throw new Error (__ ('No permission ' ), 403 );
249- } elseif (User::can ( ' mod.is_mod ' )) {
255+ } elseif (User::isAdminMod ( )) {
250256 // A moderator trying to change a user's password?
251- $ user ['select ' ] = array ('u.group_id ' , 'g.g_moderator ' );
252-
253- $ user = DB ::for_table ('users ' )
254- ->table_alias ('u ' )
255- ->select_many ($ user ['select ' ])
256- ->inner_join ('groups ' , array ('g.g_id ' , '= ' , 'u.group_id ' ), 'g ' )
257- ->where ('u.id ' , $ args ['id ' ]);
258- $ user = Container::get ('hooks ' )->fireDB ('controller.profile.change_pass_user_query ' , $ user );
259- $ user = $ user ->find_one ();
260-
261- if (!$ user ) {
262- throw new Error (__ ('Bad request ' ), 404 );
263- }
264-
265- if (!User::can ('mod.edit_users ' ) || !User::can ('mod.change_passwords ' ) || $ user ['group_id ' ] == ForumEnv::get ('FEATHER_ADMIN ' ) || $ user ['g_moderator ' ] == '1 ' ) {
257+ if (!User::can ('mod.edit_users ' ) || !User::can ('mod.change_passwords ' ) || User::isAdminMod ($ args ['id ' ])) {
266258 throw new Error (__ ('No permission ' ), 403 );
267259 }
268260 }
@@ -287,23 +279,9 @@ public function action($req, $res, $args)
287279
288280 if (!User::isAdminMod ()) { // A regular user trying to change another user's email?
289281 throw new Error (__ ('No permission ' ), 403 );
290- } elseif (User::can ( ' mod.is_mod ' )) {
282+ } elseif (User::isAdminMod ( )) {
291283 // A moderator trying to change a user's email?
292- $ user ['select ' ] = array ('u.group_id ' , 'g.g_moderator ' );
293-
294- $ user = DB ::for_table ('users ' )
295- ->table_alias ('u ' )
296- ->select_many ($ user ['select ' ])
297- ->inner_join ('groups ' , array ('g.g_id ' , '= ' , 'u.group_id ' ), 'g ' )
298- ->where ('u.id ' , $ args ['id ' ]);
299- $ user = Container::get ('hooks ' )->fireDB ('controller.profile.change_email_not_id_query ' , $ user );
300- $ user = $ user ->find_one ();
301-
302- if (!$ user ) {
303- throw new Error (__ ('Bad request ' ), 404 );
304- }
305-
306- if (!User::can ('mod.edit_users ' ) || !User::can ('mod.change_passwords ' ) || $ user ['group_id ' ] == ForumEnv::get ('FEATHER_ADMIN ' ) || $ user ['g_moderator ' ] == '1 ' ) {
284+ if (!User::can ('mod.edit_users ' ) || !User::can ('mod.change_passwords ' ) || User::isAdminMod ($ args ['id ' ])) {
307285 throw new Error (__ ('No permission ' ), 403 );
308286 }
309287 }
@@ -350,7 +328,7 @@ public function action($req, $res, $args)
350328
351329 return Router::redirect (Router::pathFor ('profileSection ' , array ('id ' => $ args ['id ' ], 'section ' => 'personality ' )), __ ('Avatar deleted redirect ' ));
352330 } elseif ($ args ['action ' ] == 'promote ' ) {
353- if (User::get ()-> g_id != ForumEnv:: get ( ' FEATHER_ADMIN ' ) && (!User::can ( ' mod.is_mod ' ) || !User::can ('mod.promote_users ' ))) {
331+ if (! User::isAdmin () && (!User::isAdminMod ( ) || !User::can ('mod.promote_users ' ))) {
354332 throw new Error (__ ('No permission ' ), 403 );
355333 }
356334
0 commit comments