How to get groups belonging to user Cartalyst Sentry 2 - database

What is the best way to get the Sentry Groups my USER model belongs to in Laravel 4.1?
I couldn't find anything in the docs about this.

The Sentry docs are pretty bare bones. You can do this to get the groups belonging to a user:
$user = User::findOrFail($id);
$user->getGroups();
foreach($user->groups as $group)
{
echo $group->name;
}

According to the sentry docs perform the getGroups() Method on the user.

Related

MsGraph get users filter to get only person account

Is there a way to list users and filter only real person account using MsGraph users API ?https://graph.microsoft.com/v1.0/users
Currently, it returns person but also conference rooms and others.
I see that you can retrieve persons you work with using people API:
https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/people?$filter=personType/class eq 'Person' and personType/subclass eq 'OrganizationUser'
Is there anything similar for users ?
Thanks you !
The current options are to either use the People API like you said or the List orgContacts endpoint from the Microsoft Graph Rest API Beta.
GET https://graph.microsoft.com/beta/contacts
This returns the list of organizational contacts for the organization.

Reinitializing rbac rights

I'm implementing RBAC in project. rbac/init command has code
$auth = Yii::$app->getAuthManager();
$auth->removeAll();
This code removing all rights and assignments. I want to save pairs users and rights in auth_assignment table. I try to make solution to save auth_assignment table data when RBAC will reinitializing
$auth = Yii::$app->getAuthManager();
$data=Yii::$app->db->createCommand('select * from auth_assignment')->queryAll();
$auth->removeAll();
Yii::$app->db->createCommand()->batchInsert('auth_assignment',['item_name','user_id','created_at'],$data);
What you think about that solution? Is it right? Thanks.
I have went through this situation and found two ways to deal with assign permissions:
First way is to work with console:
yii rbac/init
This way you have to have controller in console/command:
use Yii;
use yii\console\Controller;
class RbacController extends Controller
{
public function actionInit()
{
$auth = Yii::$app->authManager;
$auth->removeAll();
//...
}
}
Install extension yii2mod/yii2-rbac and assign roles dynamically. Here is the link .
I found the second option more productive and safe, since you keep already assigned roles saved.Hope it will helps.

IBM Watson - How to get login from user with Regex

I'm working with IBM Watson API's a few months ago.
I want to know more about Regex inside the Conversation Service. And how to get the login from the user, if they type some like:
My login is sayuri.mizuguchi!
My login? ooh, is sayuri.mizuguchi
The default is always firstname.lastname.
I want use input.text.find to get the login, and with one context variable I'll save the login, like:
{
"context": {
"loginUser": <? input.text ?>
},
Simon did the same but with other data, 11 numbers and works amazingly.
In this case I'll use just input.text because my input.text.find inside the node with IF condition will extract my data.
I find this solution with regex, #revo help with one example.
Try this inside the if condition:
input.text.find('\w+\.\w')
And only if user types login, the conversation will flow.

way to script an export of all AD users vcards

i'm looking for an easy way to export all active directory users info into unique vcards for each. there is some info i'd like to leave out of the vcard like home phone, and emergency contact. i've looked around the web and have little luck finding anything. any help would be appreciated.
I doubt there will be a very easy way. Ultimately, you need to
enumerate all your users (or a subset therefore)
iterate over the resulting list of users
export each user's data to a VCard
For the searching & iterating part, you can use a PrincipalSearcher to do your searching:
// create your domain context
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
// define a "query-by-example" principal - here, we search for a UserPrincipal
// this "QBE" user would give you the ability to further limit what you get back
// as results from the searcher
UserPrincipal qbeUser = new UserPrincipal(ctx);
// create your principal searcher passing in the QBE principal
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
// find all matches
foreach(var found in srch.FindAll())
{
UserPrincipal foundUser = found as UserPrincipal;
if(foundUser != null)
{
ExportToVCard(foundUser);
}
}
}
And now all that's left to do is create the ExportToVCard function :-) See e.g. this blog post with code samples and further links for help.
If you haven't already - absolutely read the MSDN article Managing Directory Security Principals in the .NET Framework 3.5 which shows nicely how to make the best use of the new features in System.DirectoryServices.AccountManagement. Or see the MSDN documentation on the System.DirectoryServices.AccountManagement namespace.
If you just want the data itself, I would take a look at Softerra's free LDAP Browser, found here.
Setup a profile for your directory server - once it's connected in the browser, you'll see the default schema for the BaseDN you've provided during the initial setup. On the server icon, right click, and hit "Export Data".
The export wizard will walk you through most of the process, but the important part is Step 3. If you want to find all users, just set your search filter to (objectClass=user), make sure your search scope is SubTree, and then then edit what attributes you want to return.
You'll have to process the results into VCards, but this is the easiest\fastest way of getting all the users and attributes that you want.

How to prevent user from edit someone's else post

Let's say I have User model and Post model. Post model contains field user_id.
User has $hasMany on Post and Post has $belongsTo on User.
I have some post edit action:
PostsController::edit($id) {
if($this->request->isPost())
{
$this->Post->id = $id;
$this->Post->save();
}
$post = $this->Post->read($id);
$this->set(compact('post'));
}
I use AuthComponent to login users.
How can I prevent user from editing some1 else post? Is there any cake build in function/option to do this? Because some1 can login and post edit action with any id. It's not even case of saving the post data - let's say post is private (only owner should see it) - when someone will call posts/edit/some_id it will see the edit form of this post...
The easier way is to just add this at the beginning of edit action:
$this->Post->id = $id;
if($this->Post->readField('user_id') != $this->Auth->user('id'))
{ //trigger error or redirect }
But I would have to add this at the beginning of each action that updates/reads any data that belongs to some user. So I am looking for more elegant way to do this.
Well an exact example ( handily using a Post/User model too ) is available in the cake manual
Everyones a winner!
Well there is no way of avoiding adding a line to check if a user is authorized to perform an action. Even if you use ACL (Access Control Lists), which is one of Cake's most powerful features.
But as you speak of elegance in general, ACLs will be beauty at its best :) Careful though, they've got a steep learning curve. Don't give up easy, its well worth it.
You should see ACLs from the Book http://book.cakephp.org/1.3/view/1543/Simple-Acl-controlled-Application

Resources