ܻؤ1顪30奵꡼ޥܥ

ITȤƯ30奵꡼ޥΥ饤ߥ󥰵Ͽ

2010ǯ07

20100630211430 褯ꤽʤʤ󤸤Υ̡
󤿤ܥȡ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()Ǽ桼ǡϥåʤΤǺ٥󤷤ʤȤʤߤ
    Υȥ꡼ϤƤʥ֥åޡɲ

ơ֥ΥΥפtinyint(1)ˤơsave褦Ȥͤ

  $set = array('type' => 2);
  $this->Data->create();
  $this->Data->save($set);

type2褦ȤƤɡǡ١Ƥߤ1ˤʤäƤ롪
ä餤äѤǤƤΤǡߤʤäѤϥޤ͡
ʤߤCakePHP1.3Ǥ

Cakephptinyintbooleanˤ餷ʤƤä

CORE/libs/model/datasources/dbo/dbo_mysql.php line474
    if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
      return 'boolean';
    }

ϼºθƤߤʤȵŤʤ͡
̵̤˻֤Ȥ줿
    Υȥ꡼ϤƤʥ֥åޡɲ

ΥڡΥȥåץ