L8 looking for email not user_email
LadyNay opened this issue · comments
Good afternoon,
I just finished setting up the package on a fresh Laravel 8 install and adjusted the .env to connect to the mysql connection of the wordpress database and made the changes specified in the read me. When I try logging in, it is still looking for email in the wp_ tables.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select * from wp_users
where email
= admin@127.0.0.1 limit 1)
I've even tried changing the users $fillable to the standard wp_ requirements. user_login, user_email, user_pass
the config/database and config/app has also been changed to what the readme says. Any assistance would be great :).
I am also getting this:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from wp_users
where email
= admin@127.0.0.1 limit 1)
you can use user_login
like this
Auth::guard('wordpress')->attempt([
'user_login' => '',
'user_pass' => '',
]);
you can use user_login
like this
Auth::guard('wordpress')->attempt([
'user_login' => '',
'user_pass' => '',
]);
I am finding this same error is occuring. Using attempt
works for logging in, but for password resets the SQL is still trying to use the email
column - when using Password::sendResetLink()
. Has anyone found a fix for this issue?
Hey :), try check the following:
User.php (model)
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
use StriderTech\PeachPayments\Billable;
class User extends Authenticatable
{
use HasFactory, Notifiable, HasApiTokens, Billable;
protected $table = 'users';
/**
* Disable timestamps
*
* @var boolean
*/
public $timestamps = false;
/**
* Define primary key
*
* @var string
*/
protected $primaryKey = 'ID';
/**
* The column name of the "remember me" token.
*
* @var string
*/
protected $rememberTokenName = false;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'user_registered',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'user_pass',
'remember_token', // disabled via protected property
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_login',
'user_pass',
'user_nicename',
'user_email',
'user_url',
'user_registered',
'user_activation_key',
'user_status',
'display_name',
];
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @return void
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
// Set connection via config explicitly.
$this->setConnection(config('wordpress-auth.connection', 'mysql'));
}
/**
* Accessor to update password via Auth scaffolding
*/
public function setPasswordAttribute($value)
{
$this->attributes[$this->getPasswordColumnKey()] = $value;
}
/**
* Return the key used for email in wordpress schema
*
* @return string
*/
public function getEmailColumnKey()
{
return config('wordpress-auth.options.email_column', 'user_email');
}
/**
* Return the key used for password in wordpress schema
*
* @return string
*/
public function getPasswordColumnKey()
{
return config('wordpress-auth.options.password_column', 'user_pass');
}
/**
* Get the e-mail address where password reset links are sent.
*
* @return string
*/
public function getEmailForPasswordReset()
{
return $this->{$this->getEmailColumnKey()};
}
/**
* Return password value
*
* @return string
*/
public function getAuthPassword()
{
return $this->{$this->getPasswordColumnKey()};
}
/**
* Usage for notifiable for email
*
* @return string
*/
public function routeNotificationForMail()
{
return $this->getEmailForPasswordReset();
}
}
Then under config/wordpress-auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Separate Database Connection
|--------------------------------------------------------------------------
|
| You can define your own connection other than the default one in
| database.php to use multiple connections/database in one.
|
*/
'connection' => 'wp-mysql',
/*
|--------------------------------------------------------------------------
| WordPress Customized Options
|--------------------------------------------------------------------------
|
| Due to any reason if you plan to change your wordpress schema or
| make usage of any additional column cab be defined here.
|
*/
'options' => [
/*
|--------------------------------------------------------------------------
| WP Column Mapping
|--------------------------------------------------------------------------
|
| Following option will help laravel auth scaffolding to work with
| wordpress default (or customizeable) column names
|
*/
'force_wp_email' => true,
'force_wp_password' => true,
/*
|--------------------------------------------------------------------------
| WP Email Column
|--------------------------------------------------------------------------
|
| If you're using any other column name other than default `user_email`
|
*/
'email_column' => 'user_email',
/*
|--------------------------------------------------------------------------
| WP Password Column
|--------------------------------------------------------------------------
|
| If you're using any other column name other than default `user_pass`
|
*/
'password_column' => 'user_pass',
],
/*
|--------------------------------------------------------------------------
| Password hashing configuration for Wordpress authentication
|--------------------------------------------------------------------------
*/
'hash' => [
/*
|--------------------------------------------------------------------------
| Iteration Count
|--------------------------------------------------------------------------
|
| The number of iterations used to hash the password.
| Minimum: 4, Maximum: 31
|
*/
'iteration_count' => 8,
/*
|--------------------------------------------------------------------------
| Portable Hashes
|--------------------------------------------------------------------------
|
| Should we generate portable hashes? true or false
|
*/
'portable_hashes' => true,
]
];
Thank you for your very thoughtful reply. I realized that this was actually my own issue. I was using $request->only('email')
not realizing that only()
includes the field name as well as the actual content of the field.