質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

ログイン

ログインは、ユーザーがコンピューターシステムにアクセスするプロセスの事を呼びます。

Authentication

Authentication(認証)は正当性を認証する為の工程です。ログイン処理等で使われます。

Q&A

0回答

1530閲覧

cakephp4 ログイン認証機能 ログインできない!

meruchaaan

総合スコア18

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

ログイン

ログインは、ユーザーがコンピューターシステムにアクセスするプロセスの事を呼びます。

Authentication

Authentication(認証)は正当性を認証する為の工程です。ログイン処理等で使われます。

0グッド

0クリップ

投稿2021/01/17 05:41

現在cakephp4でログイン認証機能を作成しております。
しかしログインに失敗します。
下記がデバッグで見たエラーメッセージです。

APP/Controller/ContactsController.php (line 162)

object(Authentication\Authenticator\Result) id:0 {
protected _status => 'FAILURE_CREDENTIALS_MISSING'
protected _data => null
protected _errors => [
(int) 0 => 'Login credentials not found',
]
}

controllor.php

php

1public function beforeFilter(\Cake\Event\EventInterface $event) 2 { 3 parent::beforeFilter($event); 4 $this->Authentication->allowUnauthenticated(['login']); 5 } 6 7 public function login() 8 { 9 $result = $this->Authentication->getResult(); 10 debug($result, true); 11 // 認証成功 12 if ($result->isValid()) { 13 $target = $this->Authentication->getLoginRedirect() ?? '/home0'; 14 return $this->redirect($target); 15 } 16 // ログインできなかった場合 17 if ($this->request->is('post') && !$result->isValid()) { 18 $this->Flash->error('Invalid username or password'); 19 } 20 }php 21

Application.php

php

1 2 3/////上記省略・・・・・・・・・・・・・・・・・・・・・・・・・・ 4 5 6 7public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface 8 { 9 $service = new AuthenticationService(); 10 $service->setConfig([ 11 'unauthenticatedRedirect' => Router::url('/sample/contacts/login'), 12 'queryParam' => 'redirect', 13 ]); 14 $service->loadAuthenticator('Authentication.Session'); 15 $service->loadAuthenticator('Authentication.Form', [ 16 'fields' => [ 17 'username' => 'name', 18 'mail' => 'mail' 19 ], 20 'loginUrl' => '/sample/contacts/login', 21 ]); 22 $service->loadIdentifier('Authentication.Password', [ 23 'fields' => [ 24 'name' => 'name', 25 'mail' => 'mail' 26 ] 27 ]); 28 29 return $service; 30 }

初心者なので原因もいまだに解明できていません。
もしよろしければご回答お願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問