Ion Auth - Lightweight Auth System based on Redux Auth 2 |
[eluser]Dinko[/eluser]
[quote author="adityamenon" date="1339623390"][quote author="Dinko" date="1339621424"]My question is how do you check whether the user IS logged in or not in views. For example if user is logged in i want to show admin options in widget area if he isn't logged in i want to show just login form in widget area Few things: - I don't want to have multiple views, for example one for admin, one for user, one for guest. - Right now i'm using this tutorial http://jondavidjohn.com/blog/2011/01/sca...r-ion_auth - In view files i use (!empty($someuserobject)) to see is he logged in Is there a better approach?[/quote] This is what I do: 1. Store $this->ion_auth->user() in a variable in the controller's __construct() [I use $this->user) 2. Send the user object to the view. Check inside the view if the object exists, output code accordingly. This seems very similar to what you are doing, and I don't see why we should search for better approaches when this works perfectly fine... PS: I just skimmed that tutorial and again that guy seems to be doing the same thing too![/quote] Yea, that's it. EDIT: Lil bit off topic but im struggling to get group of a user currenlty logged in. Code in my controller construct: Code: $data->the_group = $this->ion_auth->get_users_groups()->result(); Code: <?php echo $the_group->id; ?> Quote:Message: Trying to get property of non-object EDIT2: Ok, got it. $data->the_group = $this->ion_auth->get_users_groups()->result(); Chnaged to row()
[eluser]digital_frog[/eluser]
[quote author="adityamenon" date="1339622984"][quote author="digital_frog" date="1339600037"] I need to create three tiers of users:admins, students and teachers. (Admins already have a category it seems) It seems that I can use groups to separate teachers from students, but can I also use groups to classify students by their teacher's ID and their class? Also, I've read the documentation, but is it possible to apply multiple groups to a single user?[/quote] Well, you can store the teacher's ID and the class ID in the DB. That's not something IonAuth can help with, though it's very simple. Yes, you can have multiple groups for each user.[/quote] Ok, one solution is to create an extra row in the database that contains a teacher ID separate from their user ID, and all of their students will have the same teacher ID. Looking up students by teacher would simply mean matching the teacher's ID of the student with that of the teacher. Defining class could just be another row for students as well. But would it be easier to create a group for every teacher which would define their own students, and then another group based on class? Instead of using a teacher ID to track students, it would be their teacher's group. Also for the class group, it would simply be class1, class2, class3 and so forth, so all students across all teachers can use the same class groups since their teacher group will separate them. Out of curiosity, are there any tutorials for Ion_auth? I've gone through the documentation, but seeing code in action is the fastest way to learn it sometimes.
[eluser]adityamenon[/eluser]
[quote author="digital_frog" date="1339687724"] Out of curiosity, are there any tutorials for Ion_auth? I've gone through the documentation, but seeing code in action is the fastest way to learn it sometimes.[/quote] To be fair, Ion_auth is one of the better documented libraries around, the code examples are very clear on what input to give and what output to expect. Dinko's post above mine has a link to a 3rd party tutorial too. [quote author="digital_frog" date="1339687724"] Ok, one solution is to create an extra row in the database that contains a teacher ID separate from their user ID, and all of their students will have the same teacher ID. Looking up students by teacher would simply mean matching the teacher's ID of the student with that of the teacher. Defining class could just be another row for students as well. But would it be easier to create a group for every teacher which would define their own students, and then another group based on class? Instead of using a teacher ID to track students, it would be their teacher's group. Also for the class group, it would simply be class1, class2, class3 and so forth, so all students across all teachers can use the same class groups since their teacher group will separate them.[/quote] I suppose you can do it this way too. I would personally prefer having IDs to track teacher and class, as I think having so many groups will probably get messy after a while. Especially because I will then need to write code to create groups on demand, edit/delete them (and dealing with all the students they are associated with, and this might even affect classes). I tend to think Groups as a structural support to the data, and don't want to mess too much with it but only use it as a foundation. But coding is also about creativity, so go ahead, do what you are thinking, and let us know how you fared! ![]()
[eluser]digital_frog[/eluser]
While searching for info on Ion_Auth, I came across this, which might be useful to those first installing it: http://www.youtube.com/watch?v=amqmhKf4xs4 There is no sound and you'll have to pause frequently, but it helps with where the files go as well as configuration.
[eluser]Sangar[/eluser]
Hello! Ion Auth can be used with PHP-ActiveRecord? There is a way to use IonAuth through PHP-activerecord? Anyone has experience on this? Thanks!
[eluser]digital_frog[/eluser]
I'm trying to figure out some tricks with groups, and here's what I've got so far. The user's group data is not stored with the rest of their user data. There are two tables that define groups, users_groups that lists which groups a user is in, and groups which simply contains the groups' names and description. I was going through the basic admin page that came with the Ion_Auth source files and was trying to find out how to add groups to the create user form. Whenever I tried searching the table name 'users_groups' in the code though, I couldn't find anything. How can I define which group a user is in aside from the create_user() function? Also, how can I create new groups from the code? Is there a create_groups() function?
[eluser]adityamenon[/eluser]
digital_frog, can you please repeat the questions, in a numbered list format?
[eluser]digital_frog[/eluser]
The two questions were basically: 1. Is there a function that can define/modify and delete groups? 2. Is there a function that can change which group a user is in? After some more searching through ion_auth_model.php, I think I may have found the answer to question 2. I found two public functions add_to_group() and remove_from_group(). Out of curiosity, what does this line of code do that I found in that function: $this->trigger_events('add_to_group');
[eluser]adityamenon[/eluser]
1. I don't think that exists - you will need to do it manually. And there's a issue in the github regarding deleting groups, especially what happens to the users inside. I'll have to commit sometime now ![]() 2. Yes, use a combination of add_to and remove_from for editing group membership Trigger events has been explained by Ben before, here: https://github.com/benedmunds/CodeIgnite...issues/220 and here: https://github.com/benedmunds/CodeIgnite...issues/240
[eluser]sevengraff[/eluser]
Anyone familiar with how to tell how many users are loged in right now? Like get a list of everyone who logged in today/yesterday or some time limit? I see that the users table keeps track of the last login, but I don't see when this is updated. |
Welcome Guest, Not a member yet? Register Sign In |