CakePHP::携帯の端末ID(uid)で「かんたんログイン」
12月 13th, 2007 admin Posted in CakePHP, PHP |
よく考えたらCakePHPとは直接関係無いか・・・
usersテーブルでユーザ管理している場合のuidのセットとアンセット例
mobile_codeというカラムにuidを保存します。
uidの取得にはPEAR::Net_UserAgent_Mobileを使用しました。
説明不十分なところが多いですが脳内補完でお願いします。
user_controller.php
function add_mobile_code(){ //セット if(isset($this->data['set'])){ $this->cleanUpFields(); $serialNumber = $this->_getMobileUID(); $this->data['User']['id'] = $this->current_user_id; $this->data['User']['mobile_code'] = $serialNumber; if (empty($this->data['User']['mobile_code']) || $this->User->save($this->data)) { $this->Session->setFlash('かんたんログインを設定しました。'); } else { $this->Session->setFlash('かんたんログインを設定できませんでした。'); } $this->redirect('/users/add_mobile_code'); } //解除 if(isset($this->data['unset'])){ $this->cleanUpFields(); $this->data['User']['id'] = $this->current_user_id; $this->data['User']['mobile_code'] = ""; if ($this->User->save($this->data)) { $this->Session->setFlash('かんたんログインを解除しました。'); } else { $this->Session->setFlash('かんたんログインを解除できませんでした。'); } $this->redirect('/users/add_mobile_code'); } } function _getMobileUID(){ //個別IDを取得 vendor('PEAR/Net/UserAgent/Mobile'); $mobObj = Net_UserAgent_Mobile::singleton(); // get serial number $serialNumber = ""; switch( true ) { case ($mobObj->isDoCoMo()): // DoCoMoかどうか case ($mobObj->isVodafone()): // softbankかどうか if( method_exists( $mobObj, "getSerialNumber" ) ) $serialNumber = $mobObj->getSerialNumber(); break; case ($mobObj->isEZweb()): // ezwebかどうか if( isset( $_SERVER['HTTP_X_UP_SUBNO'] ) ) $serialNumber = $_SERVER['HTTP_X_UP_SUBNO']; break; default: break; } return $serialNumber; }
add_mobile_code.thtml
<h2>かんたんログインの設定</h2> <p>携帯の端末情報を登録することで次回ログインからIDとパスワードを省略できます</p> <hr /> 現在は「<?php if(!empty($me['User']['mobile_code'])){ ?>設定済み<?php }else{ ?>未設定<?php } ?>」です。 <hr /> <form action="<?php echo $html->url('/m/users/add_mobile_code/'); ?>" method="post" utn> <?php echo $html->hidden("set");?> <div class="submit"> <?php echo $html->submit('かんたんログインを設定する');?> </div> </form> <form action="<?php echo $html->url('/m/users/add_mobile_code/'); ?>" method="post" utn> <?php echo $html->hidden("unset");?> <div class="submit"> <?php echo $html->submit('かんたんログインを解除する');?> </div> </form> <ul class="actions"> <li><?php echo $html->link('トップに戻る', '/m/orders/add/');?></li> </ul>
8月 2nd, 2008 at 13:32:22
[...] [Via]CakePHP::携帯の端末ID(uid)で「かんたんログイン」 [...]