This project is read-only.

problem in assigning role to custom module

Topics: Customizing Orchard
Sep 5, 2013 at 11:31 AM
Edited Sep 5, 2013 at 11:33 AM
I have been developing a module which does not use database.......
I made it but now i want to make it role wise accessible...

n when i applied code
        var user = Services.WorkContext.CurrentUser;
in my model then it is showing user = null during debugging....

nw i donot know how to make my module role wise...

plz help me..
thanks in advance....
Sep 6, 2013 at 12:10 AM
If the user is not signed in, CurrentUser will be null.
But that won't stop you from checking permissions, which is how you should add security to your module.
To see how Permissions work, have a look at Orchard.Blogs, specifically the Permissions class. Look for references to these defined permissions to see how they are enforced.
Note: when the user is not loggedin, the Anonymous role is in effect.
Sep 6, 2013 at 7:41 AM
Sir i checked the Permission.cs class but how is it mapping to certain function.....

do we have to write services too..???

coz after logging in it still shows user = null.....
Sep 6, 2013 at 7:42 AM
Please re-read Sipke's answer carefully.
Sep 6, 2013 at 2:14 PM
actually i wanted my module to be customised role wise(means on role-id).......not permission wise.......


if (role id ==2)
do this code
if (role id==3)
do this code
Sep 7, 2013 at 5:13 AM
You should not in most cases. If you want to restrict security, permissions are definitely the way to go. If you want to present different experiences to different roles, then yes, maybe, but keep in mind that roles are not guaranteed to exist, as they can be modified, deleted and created by the site admin. Also, don't tell them apart by id (those are not guaranteed), but by name.
Sep 10, 2013 at 5:45 AM
Sir still trying to understand.......

but thanks for the guidance...
Sep 12, 2013 at 6:25 AM
Actually i got it by using session variable....