Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ログインユーザー名をカスタマイズできるよう変更 #4687

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/Eccube/Entity/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,21 @@ public function getRoles()
return ['ROLE_USER'];
}

public static function getUsernameField(): string
{
return property_exists(static::class, 'usernameField')
? static::$usernameField
: 'email';
}

/**
* {@inheritdoc}
* Get username.
*
* @return string
*/
public function getUsername()
{
return $this->email;
return $this->{static::getUsernameField()};
}

/**
Expand Down Expand Up @@ -1164,7 +1173,7 @@ public function serialize()
// CustomerRepository::loadUserByUsername() で Status をチェックしているため、ここでは不要
return serialize([
$this->id,
$this->email,
$this->getUsername(),
$this->password,
$this->salt,
]);
Expand All @@ -1187,7 +1196,7 @@ public function unserialize($serialized)
{
list(
$this->id,
$this->email,
$this->{static::getUsernameField()},
$this->password,
$this->salt) = unserialize($serialized);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Security/Core/User/CustomerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(CustomerRepository $customerRepository)
public function loadUserByUsername($username)
{
$Customer = $this->customerRepository->findOneBy([
'email' => $username,
Customer::getUsernameField() => $username,
'Status' => CustomerStatus::REGULAR,
]);

Expand Down