When I register new users, can I use custom claims to set a flag for the created user? For ex. I want to set flag 'disabled' to False when the user is enabled and
to True when I block him.
I have read in many places people saying "don't save other information rather than user role in Custom claims" but why wouldn't it be a good idea to set this flag in Custom Claims? I understand Custom Claims doesn't hold much data but a flag wouldn't be a problem I guess.
I don't see anything wrong with it. Can someone help me out with a clarification?
Related
I try to manage the access rights for users to edit or view different articles.
Articles can be created dynamically and the rights should be editable for every article.
In my case, I have a User object and multiple other objects (Article, and more...).
I need to check if a User can read or write any kind of object.
I actually see there is a method Voters, but they only can manage User groups?
Can somebody help me?
A Voter can decide almost anything - usually it's based on a user's permission, but it doesn't have to be - I've used one as a 'feature flag' check, with a value fetched from a configuration, or database entry to show something - or not, as an example.
The page on voters has an example on viewing, or editing a database record (a Post entity, via a $this->denyAccessUnlessGranted('edit', $post);.
In your instance, the voter would be passed the 'attribute', the object (Article, etc) you want to check on, and gets the current user from a service. If that user has the appropriate permission to read/edit/delete the Article or other object, it returns true.
I have a project in MVC. I would like to save a variable and have it accessible as long as the user is logged in, to get it or set it.
The reason for this is that the application uses the information I would put in there, to get data. I now need to add admin functions so an admin can see more then only his own results, and therefore I would need to change this ID, depending on what result he wants to see.
I have tried using a session, but the problem I have with that is that when the user closes the website, and at a later time returns, he is still logged in, but the session variable is null.
I also tried to add a property to my base class. I was able to set it, but when I tried to get it in a different controller, the property was null as well.
What is the best/fastest/correct way to do this? I would prefer to not use the database for this, if possible.
What you are looking for is a "Session". On login you can just do
Session["Key"] = "Value";
And on logout you can empty the field
Session["Key"] = String.Empty;
You can read more about sessions here: https://msdn.microsoft.com/en-us/library/ms178581.aspx
In order to register, users have to select a their account name created by my moderators. That means that a moderators have to create an account name before the user registers.
To do so, I made a first entity, let's call it "Member", that has a field "account". Then I added to this entity the boolean field "bound" that is set to false by default.
What I want to do is to set this field "bound" to true when someone registers after he selected his account name and fill the FOSUserBundle required fields (username, passwords, email...).
I tried to follow the documentation of "overriding controllers", but I'm getting an error (You have requested a non-existent service "fos_user.registration.form".) and this is where I'm stucked.
Using controller events can maybe help me, but I do not know which is the best solution.
If anyone has a solution to my problem, I'll be really grateful.
You should used the controller event to hook after the registration process, and more specifically the
REGISTRATION_COMPLETED event (if I remember correctly).
I am using asnet membership.
There is a role named member. In root there is a site-visitor page, on that page in page load I want to check whether member is logged-In or not i.e. profile variable has set OR not.
How can I check that?
I gave search on google as well but failed to get correct answer.
i am setting profile like -
HttpContext.Current.Profile.SetPropertyValue("UserName", UserName);
If you need to find the logged user as you indicate I want to check whether member is logged-In or no
You can use HttpContext.User Property
System.Web.HttpContext.Current.User
if(User.Identity.IsAuthenticated)
How can I add a custom user variable for the user object? I want something that a user can customize in their profile page and that I can retrieve in the user object in another module, for example a preference for currency USD or EURO.
I would accept the simplest idea that doesn't involve writing a module, unless is no other way.
You can use the Profile module to define additional settings that users will be able to edit in their profile page and will be available in the $user object: http://drupal.org/documentation/modules/profile
Furthemore, you should read How to create new profile fields.