Saturday 31 August 2019

User authentication in Laravel from xenforo database with using several tables

I have 2 databases: one from Laravel and other from XenForo 2. On Laravel, registration should not take place, but only on the forum in order to reduce data duplication and eliminate the out of sync if it happens for some reason.

There are 2 tables in XF: xf_users - stores basic user information, and xf_user_authenticate - stores a serialized array string with a password hash.

It is necessary to authenticate through these 2 tables. User entered username/password correctly - logged into Laravel CMS.

Connecting to a third-party database is simple: manually register the connection in the User model as follows:

protected $ connection = 'forum';
protected $ table = 'xf_users';
public $ timestamps = false;

I also created the Password model for obtaining passwords from the xf_user_authenticate table with a method for obtaining a password hash:

class Password extends Model
{
     protected $ fillable = ['data'];
     protected $ connection = 'forum';
     protected $ table = 'xf_user_authenticate';
     public $ timestamps = false;

     public static function getPassHash ($ uid) {
         $ data = Password :: firstWhere ('user_id', '=', $ uid) -> get ();
         return unserialize ($ data-> data) ['hash'];
     }
}

Further, as I understand it, I need to make a custom guard and provider, and here I can no longer understand what to do next...

How can I use these 2 tables for authentication in the laravel engine?



from User authentication in Laravel from xenforo database with using several tables

No comments:

Post a Comment