[Svn-src-all:1201] [version-2_5-dev 20089] 仮会員登録処理リファクタリング #985

kimoto admin @ mail.ec-cube.net
2011年 2月 4日 (金) 14:37:25 JST


Subversion committed to /home/svn/open 20089
http://svn.ec-cube.net/open_trac/changeset/20089
┌────────────────────────────┐
│更新者 :  kimoto                                       │
│更新日時:  2011-02-04 14:37:24 +0900 (金, 04  2月 2011)│
└────────────────────────────┘

Log:
--------------------------------------------------------
仮会員登録処理リファクタリング #985


Changed:                      [U:修正,A:追加,D:削除]
--------------------------------------------------------
U   branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php
U   branches/version-2_5-dev/data/class/pages/entry/LC_Page_Entry.php
U   branches/version-2_5-dev/data/class/pages/regist/LC_Page_Regist.php

変更: branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php
===================================================================
--- branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php	2011-02-04 05:37:18 UTC (rev 20088)
+++ branches/version-2_5-dev/data/class/helper/SC_Helper_Customer.php	2011-02-04 05:37:24 UTC (rev 20089)
@@ -221,7 +221,7 @@
      * @return void
      */
     function sfGetUniqSecretKey() {
-        $objQuery   = new SC_Query();
+        $objQuery   =& SC_Query::getSingletonInstance();
         $count      = 1;
         while ($count != 0) {
             $uniqid = SC_Utils_Ex::sfGetUniqRandomId("r");
@@ -229,4 +229,25 @@
         }
         return $uniqid;
     }
+
+
+    /**
+     * sfGetCustomerId
+     *
+     * @param mixed $uniqid
+     * @param mixed $check_status
+     * @access public
+     * @return void
+     */
+    function sfGetCustomerId($uniqid, $check_status = false) {
+        $objQuery   =& SC_Query::getSingletonInstance();
+        $where      = "secret_key = ?";
+
+        if ($check_status) {
+            $where .= ' AND status = 1 AND del_flg = 0';
+        }
+
+        return $objQuery->get("customer_id", "dtb_customer", $where, array($uniqid));
+    }
+
 }

変更: branches/version-2_5-dev/data/class/pages/entry/LC_Page_Entry.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/entry/LC_Page_Entry.php	2011-02-04 05:37:18 UTC (rev 20088)
+++ branches/version-2_5-dev/data/class/pages/entry/LC_Page_Entry.php	2011-02-04 05:37:24 UTC (rev 20089)
@@ -148,7 +148,7 @@
                 $this->lfSendMail($uniqid);
 
                 // 完了ページに移動させる。
-                SC_Response_Ex::sendRedirect('complete.php', array("ci" => $this->lfGetCustomerId($uniqid)));
+                SC_Response_Ex::sendRedirect('complete.php', array("ci" => SC_Helper_Customer_Ex::sfGetCustomerId($uniqid)));
             }
             break;
         default:
@@ -266,13 +266,12 @@
         $this->name01   = $arrRet['name01'];
         $this->name02   = $arrRet['name02'];
         $this->uniqid   = $uniqid;
+        $CONF           = SC_Helper_DB_Ex::sfGetBasisData();
+        $this->CONF     = $CONF;
         $objMailText    = new SC_SiteView();
         $objMailText->assignobj($this);
 
         $objHelperMail  = new SC_Helper_Mail_Ex();
-        $objCustomer    = new SC_Customer();
-        $CONF           = SC_Helper_DB_Ex::sfGetBasisData();
-        $this->CONF     = $CONF;
 
         // 仮会員が有効の場合
         if(CUSTOMER_CONFIRM_MAIL == true) {
@@ -282,6 +281,7 @@
             $subject = $objHelperMail->sfMakeSubject('会員登録のご完了');
             $toCustomerMail = $objMailText->fetch("mail_templates/customer_regist_mail.tpl");
             // ログイン状態にする
+            $objCustomer = new SC_Customer();
             $objCustomer->setLogin($arrRet["email"]);
         }
 
@@ -366,17 +366,4 @@
             }
         }
     }
-
-
-    /**
-     * lfGetCustomerId
-     *
-     * @param mixed $uniqid
-     * @access public
-     * @return void
-     */
-    function lfGetCustomerId($uniqid) {
-        $objQuery = new SC_Query();
-        return $objQuery->get("customer_id", "dtb_customer", "secret_key = ?", array($uniqid));
-    }
 }

変更: branches/version-2_5-dev/data/class/pages/regist/LC_Page_Regist.php
===================================================================
--- branches/version-2_5-dev/data/class/pages/regist/LC_Page_Regist.php	2011-02-04 05:37:18 UTC (rev 20088)
+++ branches/version-2_5-dev/data/class/pages/regist/LC_Page_Regist.php	2011-02-04 05:37:24 UTC (rev 20089)
@@ -35,9 +35,6 @@
 
     // {{{ properties
 
-    /** 設定情報 */
-    var $CONF;
-
     // }}}
     // {{{ functions
 
@@ -67,31 +64,18 @@
      * @return void
      */
     function action() {
-        $objSiteInfo = $objView->objSiteInfo;
-        $objCustomer = new SC_Customer();
-        $objDb = new SC_Helper_DB_Ex();
-        $this->CONF = $objDb->sfGetBasisData();
 
         switch ($this->getMode()) {
         case 'regist':
         //-- 本登録完了のためにメールから接続した場合
             //-- 入力チェック
-            $this->arrErr = $this->lfErrorCheck($_GET);
-            if ($this->arrErr) {
-                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", true, $this->arrErr["id"]);
+            $this->arrErr       = $this->lfErrorCheck($_GET);
+            if ($this->arrErr) SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", true, $this->arrErr["id"]);
 
-            } else {
-                $registSecretKey = $this->lfRegistData($_GET);			//本会員登録(フラグ変更)
-                $this->lfSendRegistMail($registSecretKey);				//本会員登録完了メール送信
+            $registSecretKey    = $this->lfRegistData($_GET);		//本会員登録(フラグ変更)
+            $this->lfSendRegistMail($registSecretKey);				//本会員登録完了メール送信
 
-                // ログイン済みの状態にする。
-                $objQuery = new SC_Query();
-                $arrRet = $objQuery->select("customer_id, email", "dtb_customer", "secret_key = ?", array($registSecretKey));
-                $objCustomer->setLogin($arrRet[0]['email']);
-                $etc_val['ci'] = $arrRet[0]['customer_id'];
-                SC_Response_Ex::sendRedirect('complete.php', $etc_val);
-                exit;
-            }
+            SC_Response_Ex::sendRedirect('complete.php', array("ci" => SC_Helper_Customer_Ex::sfGetCustomerId($registSecretKey)));
             break;
         //-- それ以外のアクセスは無効とする
         default:
@@ -109,69 +93,59 @@
         parent::destroy();
     }
 
-    //---- 登録
+    /**
+     * lfRegistData
+     *
+     * 仮会員を本会員にUpdateする
+     *
+     * @param mixed $array
+     * @access public
+     * @return void
+     */
     function lfRegistData($array) {
         $objQuery = new SC_Query();
 
-        do {
-            $secret = SC_Utils_Ex::sfGetUniqRandomId("r");
-        } while( ($result = $objQuery->getOne("SELECT COUNT(*) FROM dtb_customer WHERE secret_key = ?", array($secret)) ) != 0);
+        $arrRegist["secret_key"]    = SC_Helper_Customer_Ex::sfGetUniqSecretKey(); // 本登録ID発行
+        $arrRegist["status"]        = 2;
+        $arrRegist["update_date"]   = "NOW()";
 
-        $sql = "SELECT email FROM dtb_customer WHERE secret_key = ? AND status = 1";
-        $email = $objQuery->getOne($sql, array($array["id"]));
-
         $objQuery->begin();
-        $arrRegist["secret_key"] = $secret;	// 本登録ID発行
-        $arrRegist["status"] = 2;
-        $arrRegist["update_date"] = "NOW()";
-
-        $where = "secret_key = ? AND status = 1";
-
-        $arrRet = $objQuery->select("point", "dtb_customer", $where, array($array["id"]));
-
-        $objQuery->update("dtb_customer", $arrRegist, $where, array($array["id"]));
-
+        $objQuery->update("dtb_customer", $arrRegist, "secret_key = ? AND status = 1", array($array["id"]));
         $objQuery->commit();
 
-        return $secret;		// 本登録IDを返す
+        return $arrRegist["secret_key"];		// 本登録IDを返す
     }
 
     //---- 入力エラーチェック
     function lfErrorCheck($array) {
-        $objQuery = new SC_Query();
-        $objErr = new SC_CheckError($array);
+        $objErr     = new SC_CheckError($array);
 
-        $objErr->doFunc(array("仮登録ID", 'id'), array("EXIST_CHECK"));
-        if (! EregI("^[[:alnum:]]+$",$array["id"] )) {
-            $objErr->arrErr["id"] = "無効なURLです。メールに記載されている本会員登録用URLを再度ご確認ください。";
-        }
-        if (! $objErr->arrErr["id"]) {
+        if (preg_match("/^[[:alnum:]]+$/", $array["id"])) {
 
-            $sql = "SELECT customer_id FROM dtb_customer WHERE secret_key = ? AND status = 1 AND del_flg = 0";
-            $result = $objQuery->getOne($sql, array($array["id"]));
-
-            if (! is_numeric($result)) {
+            if (!is_numeric(SC_Helper_Customer_Ex::sfGetCustomerId($array["id"], true))) {
                 $objErr->arrErr["id"] = "※ 既に会員登録が完了しているか、無効なURLです。<br>";
-                return $objErr->arrErr;
-
             }
-        }
 
+        } else {
+            $objErr->arrErr["id"] = "無効なURLです。メールに記載されている本会員登録用URLを再度ご確認ください。";
+        }
         return $objErr->arrErr;
     }
 
     //---- 正会員登録完了メール送信
     function lfSendRegistMail($registSecretKey) {
-        $objQuery = new SC_Query();
-        $objHelperMail = new SC_Helper_Mail_Ex();
+        $objCustomer    = new SC_Customer();
+        $objQuery       = new SC_Query();
+        $objHelperMail  = new SC_Helper_Mail_Ex();
+        $this->CONF     = SC_Helper_DB_Ex::sfGetBasisData();
 
-        //-- 姓名を取得
-        $sql = "SELECT email, name01, name02 FROM dtb_customer WHERE secret_key = ?";
-        $result = $objQuery->getAll($sql, array($registSecretKey));
-        $data = $result[0];
+        //-- 会員データを取得
+        $result         = $objQuery->select("*", "dtb_customer", "secret_key = ?", array($registSecretKey));
+        $data           = $result[0];
+        $objCustomer->setLogin($data['email']);
 
         //-- メール送信
-        $objMailText = new SC_SiteView();
+        $objMailText    = new SC_SiteView();
         $objMailText->assign("CONF", $this->CONF);
         $objMailText->assign("name01", $data["name01"]);
         $objMailText->assign("name02", $data["name02"]);




Svn-src-all メーリングリストの案内