forked from fuel/docs
/
login.html
572 lines (532 loc) · 20.3 KB
/
login.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./../../../assets/css/combined.css">
<link rel="shortcut icon" href="./../../../favicon.ico" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
var path = './../../../';
var class_prefix = "$object->";
</script>
<script src="./../../../assets/js/combined.js"></script>
<title>Login - ドライバの種類 - Auth パッケージ - FuelPHP ドキュメント</title>
</head>
<body>
<div id="container">
<header id="header">
<div class="table">
<h1>
<strong>FuelPHP, a PHP 5.3 Framework</strong>
Documentation
</h1>
<form id="google_search">
<p>
<span id="search_clear"> </span>
<input type="submit" name="search_submit" id="search_submit" value="検索" />
<input type="text" value="" id="search_input" name="search_input" />
</p>
</form>
</div>
<nav>
<div class="clear"></div>
</nav>
<a href="#" id="toc_handle">目次</a>
<div class="clear"></div>
</header>
<div id="cse">
<div id="cse_point"></div>
<div id="cse_content"></div>
</div>
<div id="main">
<h2>Auth パッケージ</h2>
<p>Auth パッケージは Fuel における標準化された認証インターフェイスを提供します。
これにより、ユーザは自分自身で新しいドライバを書くことができ、
基本的なメソッドを保つことで、古いコードに新しいドライバを簡単に統合することもできます。</p>
<section>
<h2 id="driver_types">Auth_Login_Driver</h2>
<p>
このドライバは、すべての Auth Login ドライバの基底クラスです。抽象クラスとして定義されており、
すべての Login ドライバに汎用なメソッド、 Login ドライバが必ず実装しなければならないメソッドの
抽象メソッドの定義が含まれています。
</p>
<h3 id="driver_config">ドライバの設定</h3>
<p>
Group ドライバは必要に応じて追加のドライバをロードできます。一般的には、 Group ドライバがこれにあたります。
しかし、実装次第では、カスタムタイプのドライバを導入して利用することも可能です。そのためには、ドライバクラスに次の構造を追加してください:
</p>
<pre class="php"><code>// この Login ドライバが読み込まれたとき Simplegroup Group ドライバはオートロードされる
// このドライバが持つ追加のユーザレコードフィールドの getter を定義
protected $config = array(
'drivers' => array('group' => array('Simplegroup')),
'additional_fields' => array('profile_fields'),
);
</code></pre>
<h3 id="static">静的インターフェイス</h3>
<p>使いやすいように、Auth パッケージは Login ドライバのパブリックメソッドの静的インタフェースを提供します。
従って、Login 基底ドライバは、Group および ACL ドライバでこれらのメソッドへの静的アクセスを提供するメソッド
<kbd>member()</kbd> と <kbd>has_access()</kbd> を定義します。</p>
<p>静的インターフェースで使用するには</p>
<pre class="php"><code>// 'simpleauth' を返す
$id = Auth::get_id();
</code></pre>
<p>代わりに</p>
<pre class="php"><code>// 'simpleauth' を返す
$id = Auth::instance()->get_id();
</code></pre>
<p class="note">複数のアクティブなログインドライバに静的インタフェースを割り当てることができないように、
Auth 設定の "verify_multiple_logins" が <kbd>false</kbd> に設定されている場合にのみ使用可能です!</p>
<h3 id="generic_methods">汎用メソッド</h3>
<p>
汎用メソッドは、 Login 基底ドライバに定義されており、継承によりすべての Auth Login ドライバから使うことができます。
これらのメソッドが提供する関数には、インスタンスを生成・取得したり、 config の値を設定・取得したり、パスワードをハッシュ値にする汎用メソッドや
<a href="acl.html">ACL</a> ・ <a href="group.html">Group</a> ドライバにアクセスするものがあります。
</p>
<p class="note">クラスに定義されているメソッドのうち、ドキュメントに記載されていないものは内部で利用されてるものなので、直接呼び出さないようにしてください。</p>
<article>
<h4 id="method_get_id" class="method">get_id()</h4>
<p>ドライバのユニーク id を返します。ドライバを区別したり、特定のドライバのインスタンスを選択するために使います。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>ドライバ id の文字列</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// 'simpleauth' を返す
$id = Auth::instance('simpleauth')->get_id();
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 id="method_set_config" class="method">set_config($key, $value)</h4>
<p>ドライバの config の値を設定します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td>必須</td>
<td>config のキー名</td>
</tr>
<tr>
<th><kbd>$value</kbd></th>
<td>必須</td>
<td>config のキーの値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>void</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// config に値を設定
Auth::instance()->set_config('key', 'value');
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 id="method_get_config" class="method">get_config($key, $default = null)</h4>
<p>ドライバの config の値を取得します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$key</kbd></th>
<td>必須</td>
<td>config のキー名</td>
</tr>
<tr>
<th><kbd>$default</kbd></th>
<td><i>null</i></td>
<td>要求したキーに値がなかったときに返されるデフォルト値</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// config の値を取得し、値がなければ false を返す
$key = Auth::instance()->get_config('key', false);
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<article>
<h4 id="method_guest_login" class="method">guest_login()</h4>
<p>ドライバがゲストログイン(認証されないゲストユーザ)を許可しているかどうかを返す。 </p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>論理型</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// デフォルトインスタンスがゲストログインをサポートしているか
if (Auth::instance()->guest_login())
{
// このドライバはゲストログインをサポートしています!
}
</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">デフォルトでは、このメソッドは 'false' を返します。ゲストログインをサポートしたいときは、
このメソッドを拡張クラスでオーバーライドしてください。</p>
</article>
<article>
<h4 id="method_get_user_array" class="method">get_user_array(Array $additional_fields = array())</h4>
<p>現在ログイン中のユーザの配列を少なくとも表示名とメールアドレスを含んで返します。
追加フィールドは、ドライバの config で設定するか、 $additional_fields 配列を通じてリクエストできます。
ただし、追加フィールドが getter メソッドで取得できるように get_user_<em>フィールド名</em>() メソッドが
ドライバ内になければなりません。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$additional_fields</kbd></th>
<td><i>array()</i></td>
<td>取得するフィールド名</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>配列</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// デフォルトインスタンスのメソッドを呼ぶ
$user = Auth::instance()->get_user_array();
// 特定のインスタンスのメソッドを呼ぶ
$user = Auth::instance('simpleauth')->get_user_array();
// 静的な呼び出し("verify_multiple_logins" が false の場合)
$user = Auth::get_user_array();
</code></pre>
</td>
</tr>
</tbody>
</table>
<p class="note">'additional_fields' をドライバの設定配列に定義することで、このメソッドを呼び出したときに追加したフィールドをデフォルトで返り値に含めるようにできます。</p>
</article>
<article>
<h4 id="method_hash_password" class="method">hash_password($password)</h4>
<p>渡されたパスワードのハッシュ値を base64 エンコードで返します。このメソッドは非常にセキュアな <a href="http://en.wikipedia.org/wiki/PBKDF2">pbkdf2</a> ハッシュアルゴリズムを使用しています。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
<table class="parameters">
<tr>
<th>パラメータ</th>
<th>デフォルト</th>
<th class="description">説明</th>
</tr>
<tr>
<th><kbd>$password</kbd></th>
<td>必須</td>
<td>ハッシュ化するパスワード</td>
</tr>
</table>
</td>
</tr>
<tr>
<th>返り値</th>
<td>文字列</td>
</tr>
<tr>
<th>例</th>
<td>
<pre class="php"><code>// ユーザのパスワードをハッシュ化
$password = Auth::instance()->hash_password($password);
</code></pre>
</td>
</tr>
</tbody>
</table>
</article>
<h3 id="abstract_methods">抽象メソッド</h3>
<p>
どの自作 Login ドライバも、以下のメソッドを用意しなければなりません。また、ここで記載されたとおりに値を返さなければなりません。
</p>
<article>
<h4 id="method_perform_check" class="method">perform_check()</h4>
<p>内部のクラスメソッドで、現在のユーザについて認証済みセッションがあるかをチェックします。自作ドライバでは、このメソッドをどう定義するかを決める必要があります。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>論理型、認証済みのユーザセッションがある場合 <strong>true</strong> 、そうでなければ <strong>false</strong> 。</td>
</tr>
</tbody>
</table>
<p class="note">このメソッドは Auth::check() から呼ばれます。アプリケーションから直接呼び出さないようにしてください。</p>
</article>
<article>
<h4 id="method_validate_user" class="method">validate_user()</h4>
<p><strong>validate_user</strong> メソッドはログインを検証します。自作ドライバでは、このメソッドがどう振る舞うかを決める必要があります。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed 。ユーザからのログインリクエストが失敗した場合、 <strong>false</strong> を返す必要があります。 true と評価されうるすべての返り値は検証に成功したものとして扱われます。</td>
</tr>
</tbody>
</table>
<p class="note">このメソッドをアプリケーションから呼び出すときは、 <strong>false</strong> 以外の返り値に何がくるか決めつけてはいけません!</p>
</article>
<article>
<h4 id="method_login" class="method">login()</h4>
<p><strong>login</strong> メソッドはログインリクエストを扱います。リクエストを検証するために validate_user() 呼び出す必要があります。自作ドライバでは、このメソッドがどう振る舞うかを決める必要があります。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>論理型。ログインが成功し場合、 <strong>true</strong> を、そうでなければ <strong>false</strong> を返す。</td>
</tr>
</tbody>
</table>
<p class="note">ゲストユーザをサポートする場合は、 <strong>false</strong> を返す前にゲストを設定する必要があります。</p>
</article>
<article>
<h4 id="method_logout" class="method">logout()</h4>
<p><strong>logout</strong> メソッドは現在ログイン中のユーザをログアウトさせます。自作ドライバでは、このメソッドがどう振る舞うかを決める必要があります。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>論理型。ログアウトが成功し場合、 <strong>true</strong> を、そうでなければ <strong>false</strong> を返す。</td>
</tr>
</tbody>
</table>
<p class="note">ゲストユーザをサポートする場合は、 ログアウトの成功後にゲストを現在のユーザーとして設定する必要があります。</p>
</article>
<article>
<h4 id="method_get_user_id" class="method">get_user_id()</h4>
<p><strong>get_user_id</strong> メソッドは、 ドライバ id の値、現在ログイン中のユーザの id を配列で返します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed 。 ユーザがログイン中なら <strong>array(driver_id, user_id)</strong> 形式の配列を、そうでなければ <strong>false</strong> を返す。</td>
</tr>
</tbody>
</table>
<p class="note">ゲストユーザをサポートする場合は、 <strong>false</strong> ではなくゲストユーザーの user_id (ダミー) を配列とともに返してください!</p>
</article>
<article>
<h4 id="method_get_groups" class="method">get_groups()</h4>
<p><strong>get_groups</strong> メソッドは、現在ログイン中のユーザが属しているユーザグループを返します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed 。ユーザがログイン中なら、 <strong>array(array(driver_id, group_id), array(driver_id, group_id), etc)</strong> 形式の配列を、そうでなければ <strong>false</strong> を返す。</td>
</tr>
</tbody>
</table>
<p class="note">ゲストユーザをサポートする場合は、 <strong>false</strong> ではなくゲストユーザーのグループの配列を返してください!</p>
</article>
<article>
<h4 id="method_get_email" class="method">get_email()</h4>
<p><strong>get_email</strong> メソッドは、現在ログイン中のユーザに対応するメールアドレスを返します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed 。 ユーザがログイン中ならメールアドレスを、現在のユーザにメールアドレスがない場合やログイン中のユーザがいない場合は <strong>false</strong> を返す。</td>
</tr>
</tbody>
</table>
<p class="note">ゲストユーザをサポートする場合は、ゲストユーザ用にメールアドレスを指定していないときに <strong>false</strong> を返すことを忘れずに!</p>
</article>
<article>
<h4 id="method_get_screen_name" class="method">get_screen_name()</h4>
<p><strong>get_screen_name</strong> メソッドは、現在ログイン中のユーザの表示名を返します。</p>
<table class="method">
<tbody>
<tr>
<th class="legend">静的</th>
<td>いいえ</td>
</tr>
<tr>
<th>パラメータ</th>
<td>
なし
</td>
</tr>
<tr>
<th>返り値</th>
<td>mixed 。表示名の文字列を返す。ログイン中のユーザがいなければ <strong>false</strong> を返す。</td>
</tr>
</tbody>
</table>
<p class="note">ゲストユーザをサポートする場合は、 <strong>false</strong> ではなくゲストの表示名を返してください!</p>
</article>
</section>
</div>
<footer>
<p>
© FuelPHP Development Team 2010-2013 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
[ <a href="https://github.com/fuel/docs/commits/1.7/develop/packages/auth/types/login.html">原文コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/commits/1.7/develop_japanese/packages/auth/types/login.html">翻訳コミット履歴</a> | <a href="https://github.com/NEKOGET/FuelPHP_docs_jp/blob/1.7/develop_japanese/packages/auth/types/login.html">GitHubで修正</a> ]
</p>
</footer>
</div>
</body>
</html>