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:
class Password extends Model
{
protected $ fillable = ['data'];
protected $ connection = 'forum';
protected $ table = 'xf_user_authenticate';
public $ timestamps = false;
}
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?
I solved this problem by means changing User model:
class User extends Authenticatable
{
use Notifiable;
protected $fillable = ['username', 'email', 'password', 'user_state'];
protected $connection = 'forum';
protected $table = 'xf_user';
protected $primaryKey = 'user_id';
public $timestamps = false;
public function getAuthPassword(){
$password = Password::where('user_id', '=', $this->user_id)->select('data')->first();
return unserialize($password->data)['hash'];
}
}
Using this model, user from XF logins fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With