In my Synfony2 wep application, there is two different role that the same user can have. He can whether be an employee or a boss. So, I want to have a switch button the change role so the user have a different view on data. For example, has a Boss the user would see the progress of the work in a project and as a Employee he would see the work to be done from each member of the team in the same project. So basically, the boss would have privilege on some action and the employee on some others.
How should I do the switch between the roles? I was planning to have two different url for each roles /boss/todesand employee/todos. In some case, I would use the same twigs template (e.g. the listing of the todos). How do I do when I need to generate a URL such as /boss/todos/{id} by always specifying the same route_name path('todo_show', {'id': id}).
I think it is pretty similar to the _locale parameter. Is it possible to create a custom parameter similar to _locale in Symfony 2.3?
Thanks in advance !
IMO you think too complex. Create one route for both users, say /todo/{id} which will redirect user based on their role to the user specific route /boss/todo/{id} or /employee/todo/{id}.
setting a default parameter in your routing config file is not enought?
todo_show:
pattern: /{_user}/todos/{id}
defaults: { _controller: YourAppBundle:Default:getTodos, _user: boss }
requirements:
_user: boss|employee
methods: [GET]
and then:
path('todo_show', {'id': id, '_user': 'employee'}); // for boss there is no need to specify _user
Related
I having some thoughts about what is the most right way to do the develop platform interface for project which grab it's all data from external API.
This platform has few account types, which i currently store in session after the user logging in.
for the example i will use 3 account types :
Admins
Sellers
Buyers
What I need :
each account type will use same routing path's but - will rendered different templates. for ex.
route '/' for admin user will render 'admin-dash' template, and so for 'buyer-dash' and 'seller_dash'
I am storing the account type on session,
Session('userRole', 'admin'/'seller'/'publisher');
and if the user is a seller or publisher I am adding an 'account-id' value to the session also, so I will be make use of when i will need to pull data for the current account.
The question is, if can i declare different routes for same path, by the current session data.
So what do you suggest ?
Thanks!
Router.route('/', function () {
var userType = Session.get('userRole');
if(userType == 'admin')
{
this.render('admin-dash');
}
else if(userType == 'buyer'){
this.render('buyer-dash');
}
});
this is how I think you can achieve your goal.
Currently building a WordPress intranet site, that authenticates users using Auth.0 SSO, against the company's Azure AD. The SSO functions properly, but I'm trying to get more granular with access control using Auth.0's "rules". The ideal result is a rule that specifies (updates) the user's WP Profile with a user role based on their job title from AD. The code below has been modified from one of Auth.0's rule templates, and runs clean. However, it doesn't work - I'm not sure what particular arguments/functions I need to actually update the role in WordPress. I'll be up-front and admit that I'm far from proficient in JS. Any thoughts?
function (user, context, callback) {
if (user.job_title === 'IT/Marketing Coordinator') {
user.vip = true;
}
callback(null, user, context);
}
In the example above, it successfully sets "user.vip" to "true" (which really doesn't prove much except that the rule executes without error.
this rule, as you said, is fine and will add this attribute.
The issue is that you will need to do something from the wordpress side to make it work (that the user has a vip flag doesn't mean anything to WordPress).
What you can do is hook to the auth0_user_login action that is fired each time a user logs in and based on the user profile set/change the user role.
This is how you hook to the action:
add_action( 'auth0_user_login', 'auth0UserLoginAction', 0,5 );
function auth0UserLoginAction($user_id, $user_profile, $is_new, $id_token, $access_token) {
...
}
I think you will find this WP doc useful to update the user role: https://codex.wordpress.org/Function_Reference/wp_update_user
What I am trying to achieve is:
1) I have a Profile2 field in the user registration form called: "Firm Type"
2) I need to assign the new user a Role based on the selection in this field.
I have tried the following:
Event: After saving a new account
Condition: Data Comparison: account:profile-additional-registration-info:field-profile-firm-type
Action: Add a user role
The above Rule works fine when I remove the condition. As soon as I add the condition the rule does not work.
Digging into this I found out that Rule gets executed after Account is saved and before Profile2 is saved.
I looked online to find these 2 links helpful:
https://www.drupal.org/node/1872384
https://www.drupal.org/node/2009878
1 suggestion was:
Event: After saving a new profile
Condition: Data Comparison: Profile2:field
Action: Heres where the problem is -- I cannot get to the account level because its on a profile event.
Could you please help me figure this out. Any help would be really appreaciated!
Thanks!
Here are the steps:
Rules Event: After adding a new profile After updating an existing profile
Rules Condition: Negate User Has Roles: Check all roles other than a Public Role Data Comparison: profile2:field
Rules Action: Set a Data Value: site:current-user:roles
I am using symfony 2.5 and trying to check if a user has a specific role. The tables are set up correctly in the database and the data is correct inserted:
In the database exists a user test#example.com with a mapped group admin which has defined the roles a:1:{i:0;s:10:"ROLE_ADMIN";}
I don't know why the roles aren't read correct. The debug-toolbar tells me, that i am only authenticated as ROLE_USER.
Code:
$securityContext = $this->container->get('security.context');
$securityContext->isGranted('ROLE_ADMIN');
if ($securityContext->isGranted('ROLE_ADMIN')) {
echo 'crazy coding magic happens here';
}
I have found this question (Symfony 2 FOS UserBundle users doesn't get group's role) which seems to be related to my question, but i am not satisfied with the answer, because i don't want to check the group-access but the role-access. In my case group permissions could change in the future.
Thanks for your help!
Okay - it seems i have found the solution by myself.
The problem is that you have to sign off the logged in user and sign in again to recognize changes in the group-role-mapping.
The code above is correct and after the is user is logged in again the correct roles are assigned.
I need to provide a pageId on every URL however I don't need the user to see this pageId. For example
http://{domain}/{product-name}/{product-id}/{pageid} <-- I don't want to provide this
I have in my Global.asax:
routes.MapPageRoute("route-name", "path/{productName}/{product-id}", "~/ProductPage.aspx");
Is there some way to configure this route so it has a "hard coded" parameter page id for example something like this ---
routes.MapPageRoute("route-name", "path/{productName}/{product-id}", "~/ProductPage.aspx?pageid=1");
Is there some way to configure this route so it has a "hard coded"
parameter page id
Why yes... yes there is.
MapPageRoute has an overload that accepts a set of defaults for route values.
//Create route and set default values
routes.MapPageRoute(
"route-name",
"path/{productName}/{product-id}",
"~/ProductPage.aspx",
false,
new RouteValueDictionary{
{"product-id", 1}
});
So now if you hit this route without a "product-id" specified, it will always default to 1