Meta table(s?) in Ion Auth (Codeigniter) - php

I'm hoping to use Ion Auth for a Codeigniter application, but I'm unsure of exactly how to structure the tables appropriately. Basically, I have a few different types of users each with different attributes. How would one build this out with just a single meta table?
Some ideas were offered here ( Create user roles and profiles in Codeigniter using Ion Auth ) but none seem particularly elegant or ideal. Is there a a better way? Can I easily work with multiple meta tables (e.g. meta_type1, meta_type2, etc.) somehow?
A related issue pertains to the "identity" config parameter for login etc. How could I have the identity be email for one user type, and username for another?
Thanks in advance for any tips/advice/ideas

Ion Auth code is really clean and organized.
You can easily hack the login process to accept both username or email. Even better, you can fork the repo on GitHub and make the $config['identity'] variable accept both string or array, and act according to that. And send a pull request! :-)
Regarding meta data for users: I would definitely use a single table to handle users metadata. You can put several columns and set to null in case some user type doesn't need them.
Hope my ideas help! Good luck and happy coding.

I also meet the same problem as you. And i found codeigniter authentication library alternative that could solve the problem. Flexi Auth seems can handle "multiple extra meta table" for different user groups.

Related

Seeding Laravel DB from external API

I'm new to Laravel. Maybe my questions are a little bit silly... Sorry...
The goal: There are some API resources and I need to take some selective data from them (It will be needed to make extra API queries from data which I already got before to get full sets of required values) and fill my DB tables with it (some as one to many, some as many to many).
The problem: What Laravel tools do I need to use to reach this goal? Is it factory, seeder or somewhat else? In addition I don't understand where I have to write the code for getting data from an external API and where (in terminal manually?) I have to initiate my DB tables filling.
Maybe someone could at least advise what to learn in the Laravel official documentation at first or some helpful reference to some article from which I will be clear how this process may be implemented in Laravel. I mean the tools' set and order to use them. Not the finished code implementation of course.
I will be grateful for any help. Thanks. Sorry for my non native English.
Well, there are multiple ways of achieving what you want:
One is to create a command where you are going to write code to fetch this data (using curl or any similar way). And then you manually run the command when you want with whatever arguments you want.
Other one is to use the previous step and schedule it to run in a desired time with desired arguments.
Other possible way is, if the external API can send data to a specific URL when some action occurs in that system, then you can create a normal Route and the API should point to this Route in your Laravel. It will be specific and only work for this API.
Other one is to fetch data based on an event. Let's say that, if a user register, when this is successful, you are going to fetch User info from an external API using their email (let's say you want to get a profile picture from an API and the only way to get the user picture is sending the user's email). You can do so using Events.
There are more ways, but if you don't give too much context, then this is what I can share with you !

Only using specific methodes of FOSUserBundle

I'm building a website with symfony and for the user management I choose FOSUserBundle. Now.. I've build my form where I need an username, email and password (nothing more for now), which are the fields in my User table. But with FOSUserBundle it expects a lot more fields in my table like username_canonical, token, login_confirmation....
Is there a way to still use FOSUserBundle, but only with the 3 fields that I want to use? I was searching to maybe override it, but I couldn't find a solution.
In order to use FOS\UserBundle your user class needs to implement FOS\UserBundle\Model\UserInterface. It will provide the mandatory information. If you really want to have a simpler user interface (although FOS\UserBundle\Model\UserInterface is pretty simple) you will need to create your own logic (e.g. fork FOS\UserBundle).

Codeigniter Ion Auth editing users table

I'm new to Codeigniter and am just learning about the ion auth authentication system. I just have a few questions about it:
1) Is it possible to modify the default users table? (and would you advise for or against it?) I understand that there may be functions in the model, view, library or controller that expect the tables to have their exact default structures but for example, i have no need for a company column, so how can i go about removing it?
2) How can i add additional user information to the default users table? (Will it affect any functions if i just execute some sql to add columns to the default users table?)
3) This is kind of a follow on from theast question, would anyone recommend just creating a separate table for my additional user information and using their user id as the primary key in this new table and then just accessing tjat information via my own models?
Thanks for all your help!
Yes, it's possible to edit the users table, you will, however, have to go through the ion_auth_model / library to check for calls/writes to the field you are deleting. Otherwise you'll experience 500 errors for trying to insert data to a non-existent field.
Yes, you can add additional fields in phpmyadmin where you have access to the database itself. The additional fields will either need to be set to null (to prevent errors on writing if the data isn't present), OR you'll have to include those fields as required and add them to ion_auth's existing functions.
Solid idea, usually the rule I go by is keeping as little null fields as possible in the database. So if every user will have additional information, and you aren't expanding your table to a ridiculous length, then I'd append it to the users table. Otherwise, if you are adding optional additional fields, it's probably better to do an associative table.
Don't forget that you're the developer, libraries are used for convienice and security, but don't feel like you can't tailor them to better suit your needs. That's how we get cookie cutter applications.
Adding/removing fields to the default users table in the database is okay as long as you remove the associated code in Ion Library that depends on it. I encourage you to fork the Ion Authentication library and modify it as it fits your requirements.
If you want to leave the Ion Library unmodified, creating another table to store additional information is the right approach.
For modifying database tables/fields, using CodeIgniter's migration is recommended so that you can keep track of database changes inside a source code repository such as Git.

How to setup multiple authenticators for users

I'm writing an application in PHP using Yii. I'm trying to add the ability for users to be able to be authenticated differently.
My main question is what is the best way to go about it.
For example, I was thinking of doing something like so:
Have a table of Authenticators in a database that correlates to classes.
In the users table, have an authenticator id column that correlates to an authenticator.
This is about where I get stuck. I'm trying to be a Yii as possible here and use ActiveRecord. Each authenticator would need to know the users ID, so I'd have to pass that to the authenticator model (that stores the class name) and then find a way to pull the actual class, while passing the user to that as well.
All this seems a bit ... over kill.
Any guidance would be greatly appreciated.
Thanks!
Kyle
Just create your own descendant of CUserIdentity which implements Factory pattern. Sounds difficult, but I think there's no short answer at all.
You have all your answers in this topic: Authentication and Authorization.
i'm suggesting you to use rbac approach and the easiest way is to use right module.

CakePHP Authentication - Username and Password in different tables

I have the following tables:
People
Users
Emails
The user's password is stored in the Users table and I want them to use their default email address which is stored in the Emails table to authenticate. The email is indicated as their default by a boolean column in the Emails table.
How do I use CakePHP's Authentication component in this setup?
I think you shoulnd't split the info in separate tables. Put everything in your Users table, and then make one-to-one relationships.
Anyway, if you want to do it this way you should override the login() method in the UsersController.
Here you have an example: http://bakery.cakephp.org/articles/SeanCallan/2007/04/17/simple-form-authentication-in-1-2-x-x
This is the method you need to override:
http://api13.cakephp.org/class/auth-component#method-AuthComponentlogin
EDIT:
Make your auth data depends on Users only. I mean, put email, username (if you have one), and password there. After that, if you have, for example, People table to record other info (first name, addres, phone, etc), make an one-to-one relationship with that table. If you have your Customer table, and your customer can be users, make a one-to-one relationship.
I ran into this troubles some time ago, and was useful to solve it as Django do, and is with this one-to-one solution.
This answer should be enough evidence that you will not be able to use multiple models for your Auth component. It only supports a string, not an array. But if you keep reading, there might be a work around for you.
Create a /app/Controller/Component/Auth/MyFormAuthenticate.php file, and setup Auth to use MyForm instead of Form for authentication.
In this file include the authenticate function and the _findUser function.
You then need to override the _findUser function to suit your needs.
Thanks to Ceeram on the CakePHP freenode channel for this solution.

Categories