質問するログイン新規登録

質問編集履歴

5

誤字修正

2017/09/28 05:49

投稿

massy7
massy7

スコア45

title CHANGED
File without changes
body CHANGED
@@ -72,13 +72,27 @@
72
72
  'app.users'
73
73
  ];
74
74
  ```
75
+ loginAction
76
+ ```php
77
+ public function login()
78
+ {
79
+ if($this->request->is('post')){
80
+ $user = $this->Auth->identify();
81
+ if($user){
82
+ $this->Auth->setUser($user);
83
+ return $this->redirect($this->Auth->redirectUrl());
84
+ }
85
+ $this->Flash->error('ユーザー名かパスワードが間違ってます.');
86
+ }
87
+ }
88
+ ```
75
89
  と読み込んでおり、ログイン画面にPostしたところ、リダイレクトは通ります($this->assertResponseSuccessで判定、実際はログイン成功時はindexへ、失敗時はloginへ)、assertSessionの値が合いません。
76
90
  つまりログインできていないのでしょうか?
77
91
  また、
78
92
  ```php
79
93
  $this->assertRedirect(['controller' => 'CONTROLLER', 'action' => 'index']);
80
94
  ```
81
- がNo location header set.となってしまうため、リダイレクトが正しいかの判断ができません。
95
+ がNo location header set.となってしまうため、リダイレクトが正しいかの判断ができません。
82
96
 
83
97
 
84
98
  よろしくお願いします。

4

修正

2017/09/28 05:49

投稿

massy7
massy7

スコア45

title CHANGED
File without changes
body CHANGED
@@ -72,8 +72,8 @@
72
72
  'app.users'
73
73
  ];
74
74
  ```
75
- と読み込んでおり、ログイン画面にPostしたところ、リダイレクトは成功します(ログイン成功時はindexへ、失敗時はloginへ)、assertSessionの値が合いません。
75
+ と読み込んでおり、ログイン画面にPostしたところ、リダイレクトは通ります($this->assertResponseSuccessで判定、実際はログイン成功時はindexへ、失敗時はloginへ)、assertSessionの値が合いません。
76
- つまりログインできていない?
76
+ つまりログインできていないのでしょうか
77
77
  また、
78
78
  ```php
79
79
  $this->assertRedirect(['controller' => 'CONTROLLER', 'action' => 'index']);

3

修正

2017/09/28 05:45

投稿

massy7
massy7

スコア45

title CHANGED
File without changes
body CHANGED
@@ -69,9 +69,6 @@
69
69
  test
70
70
  ```php
71
71
  public $fixtures = [
72
- 'app.callLogs',
73
- 'app.customers',
74
- 'app.holidays',
75
72
  'app.users'
76
73
  ];
77
74
  ```

2

追記

2017/09/28 05:44

投稿

massy7
massy7

スコア45

title CHANGED
File without changes
body CHANGED
@@ -53,4 +53,35 @@
53
53
  ]);
54
54
  ```
55
55
 
56
+ ### 追記
57
+ UsersFixture
58
+ ```php
59
+ public $records = [
60
+ [
61
+ 'id' => 1,
62
+ 'user_id' => 'test',
63
+ 'email' => 'test@test.co.jp',
64
+ 'password' => 'test',
65
+ 'deleted' => 0
66
+ ],
67
+ ];
68
+ ```
69
+ test
70
+ ```php
71
+ public $fixtures = [
72
+ 'app.callLogs',
73
+ 'app.customers',
74
+ 'app.holidays',
75
+ 'app.users'
76
+ ];
77
+ ```
78
+ と読み込んでおり、ログイン画面にPostしたところ、リダイレクトは成功します(ログイン成功時はindexへ、失敗時はloginへ)、assertSessionの値が合いません。
79
+ つまりログインできていない?
80
+ また、
81
+ ```php
82
+ $this->assertRedirect(['controller' => 'CONTROLLER', 'action' => 'index']);
83
+ ```
84
+ がNo location header set.となってしまうため、リダイレクト作が正しいかの判断ができません。
85
+
86
+
56
87
  よろしくお願いします。

1

文章修正

2017/09/28 05:41

投稿

massy7
massy7

スコア45

title CHANGED
File without changes
body CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  ###発生している問題・エラーメッセージ
9
9
  ```php
10
+ // テスト
10
11
  $this->session(
11
12
  [
12
13
  'Auth' => [
@@ -24,8 +25,9 @@
24
25
  ```
25
26
  で、どんなデータを入れてもログインに成功(リダイレクトされず、assertResponseOkが通る)してしまう。
26
27
 
27
- 実際のブラウザでは当然間違ったログインは弾かれます。
28
+ 実際のブラウザでは当然間違ったログインは弾かれるようにしています。
28
29
  ```php
30
+ // コントローラ
29
31
  $this->loadComponent('Auth',[
30
32
  'authorize' => 'Controller',
31
33
  'authenticate' => [