���󤿤��������ܥ���ȡ�ID/PASS���Ϥ���ե����ࡣ
���󤿤��������Ϥ�����������ޤ����ɡ��Ȥꤢ��������Ͽ���ޤ���
����ꥢ�Υ����ȥ�������IP���¤Ϥ��ޤ��礦�äƤ��󤸡�
ɸ���Auth����ݡ��ͥ�Ȥȡ�ktai�饤�֥����ȤäƤޤ���
UID�����ꤷ�Ƥ���С֤��󤿤��������פǤ��ơ����Ƥʤ����ID/PASS���Ϥ���UID���ꤹ�뤳�Ȥ�Ǥ���Ȥ�����ǽ��
����ϥȥåץڡ����ǹԤ�����Ǥ���
Cake�ΥС�������1.3
APP/controllers/top_controller.php
class TopController extends AppController { var $name = 'Top'; var $uses = 'User'; var $helpers = array('Ktai','Session','Form'); var $components = array('Ktai','Session','Auth'); function beforeFilter() { $this->Auth->loginAction = '/'; $this->Auth->autoRedirect = false; $this->Auth->authorize = 'controller'; $this->Auth->allow('index'); parent::beforeFilter(); } function beforeRender() { parent::beforeRender(); } function index () { if ($user = $this->Auth->user()) { if (isset($this->data['add_uid'])) { $user['User']['uid'] = $this->Ktai->get_uid(); $this->User->save($user['User']); /* 7/14�ɵ� */ $user = $this->User->findById($set['id']); $this->Auth->login($user); /* 7/14�ɵ������ޤ� */ } $this->redirect($this->Auth->redirect()); } else { if (isset($this->data['auto_login'])) { if ($user = $this->User->findByUid($this->Ktai->get_uid())) { if ($this->Auth->login($user['User'])) { $this->redirect($this->Auth->redirect()); } else { $this->Session->setFlash('���٤��󤿤������������򤷤Ƥ�������',null); } } else { $this->Session->setFlash('���󤿤�����������꤬����Ƥ��ޤ���',null); } } } } function isAuthorized () { $user = $this->Auth->user(); $user['User']['last_login'] = date('Y-m-d H:i:s'); $this->User->save($user['User']); return true; } }
��äƤ��뤳�Ȥϰʲ���3����
��ID/PASS�ǥ��������������ơ��֤��󤿤�����������ꤹ��פ˥����å�������Ƥ���С�UID��Ȥäƥơ��֥���ͤù��ࡣ
�����󤿤��������ξ���UID�ò¥¡ï¿½ï¿½ï¿½users�ơ��֥뤫��ǡ������äƤ���Auth->login���ͤù���ǥ������󤵤��롣
��isAuthorized()�ǥ�����������������������������򹹿���
users�ơ��֥�
+-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | id | int(10) | NO | PRI | NULL | auto_increment | | username | varchar(100) | NO | | NULL | | | password | varchar(100) | NO | | NULL | | | uid | varchar(100) | NO | | NULL | | | flag | int(1) | NO | | NULL | | | last_login | datetime | NO | | NULL | | | created | datetime | NO | | NULL | | | updated | datetime | NO | | NULL | | +-------------+--------------+------+-----+---------+----------------+
�������å������Ȥ��ʤ����Ӥ��ޤ��ޤ��������󤢤뤿��ʼ��docomo�ˡ����Τ���������˺��ʤ��褦�˥�⡣
APP/config/bootstrap.php
if (!isset($_SESSION)) { if ($ini_set) { ini_set('session.use_trans_sid', 1); ini_set('session.serialize_handler', 'php'); ini_set('session.use_cookies', 0); } }
2010/07/14�ɵ�
��������κݤ�UID��ơ��֥���ɲä�����硢
$this->Auth->user()�Ǽ���桼���ǡ����ϥ��å����ʤΤǺ��٥������󤷤ʤ��Ȥ����ʤ��ߤ�����