The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
php script to add user to group
#1
does any one know to add the currently logged in user to a permissions group.
  Reply
#2
I can't think of a way to do that. It seems like it would be a security vulnerability.

I think the better thing to do would be something along the lines of putting...
Code:
if($user->isLoggedIn()){
Code:
//your code here
Code:
}

somewhere on the page to make something accessible to only logged in users. Maybe I'm missing something.

Can you tell me a little bit more about what you're trying to accomplish?
  Reply
#3
I need to add users to a group with out manually doing it. is there any way of doing that
  Reply
#4
Sure. Let me think through that.
  Reply
#5
Ok. So when you're on the admin_permissions.php page and you click on a permission, you'll see that each permission level has an id. By default, User level is id 1, Administrator is id 2. As you add more, they go up. I'm guessing you want to add a third level. Take note of its id. (Let's assume it's 3).

So, the user will have to go to a particular page to trigger the "check" to add them to this permission group. Let's assume it's the default account.php. Somewhere at the top, you'll need to add a php check to see if they already have the proper permission.

Code:
<?php
Code:
$check = $db->query("SELECT * from user_permission_matches WHERE user_id = $user->data()->id AND permission_id = 3");
Code:
$count = $check->count();

Code:
if($count<1) { //meaning that permission was not found for that user
Code:
$fields=array('user_id'=>$user->data()->id, 'permission_id'=>3); //column_name=>entry
Code:
$db->insert('user_permission_matches',$fields);
Code:
}
Code:
?>

This is totally off the top of my head, but should point you in the right direction. If you get stuck, let me know.
  Reply
#6
Yes this helps a ton. Thank you.
  Reply
#7
Works great
  Reply
#8
Awesome! I was a little rusty in my mind on some of that stuff. I'm glad it worked.
  Reply
#9
For some odd reason this stopped working. I tried everything. I just did a fresh install and it still was not working. I have tried it on 2 different servers with different hoses here is the code i am using.
  Reply
#10
I'm not seeing your code. Can you paste it on hastebin and give me the link?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)