Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
MYSQL_VERSION: ${{ matrix.mysql }}
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: cakephp_test
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2
Expand Down
30 changes: 29 additions & 1 deletion Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function beforeValidate($options = array()) {
*/
protected function _setUsernameValidate() {
//ログインID
if (! Hash::get($this->data, 'User.id')) {
if ($this->__isValidateUsernameRequired()) {
$this->validate = ValidateMerge::merge($this->validate, array(
'username' => array(
'notBlank' => array(
Expand Down Expand Up @@ -334,6 +334,34 @@ protected function _setUsernameValidate() {
}
}

/**
* ログインID(username)のバリデーションを行うかどうか
*
* @return bool
*/
private function __isValidateUsernameRequired() {
if (!Hash::get($this->data, 'User.id')) {
// 新規登録ならば、必ずバリデーションを行う
return true;
}
// 更新時
if (!isset($this->data['User']['username'])) {
// ログインID(username)がPOSTされてなければバリデーション不要
return false;
}
$beforeUser = $this->find('first',
[
'conditions' => [
'id' => $this->data['User']['id']
],
'recursive' => -1,
'fields' => ['username']
]
);
// ログインID(username)が変更されてなければバリデーション不要。変更されてたらバリデーション必要
return $beforeUser['User']['username'] !== $this->data['User']['username'];
}

/**
* バリデーションのセット(パスワード)
*
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.5
3.3.6