source: branches/version-2_5-dev/data/class/pages/entry/LC_Page_Entry.php @ 20085

Revision 20085, 14.5 KB checked in by kimoto, 13 years ago (diff)

会員登録リファクタリング #979
sfCheckRegisterUserFromEmailを有効活用させていただきました

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_REALDIR . "pages/LC_Page.php");
26
27/**
28 * 会員登録のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_Entry.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Entry extends LC_Page {
35
36    // {{{ properties
37
38    /** フォームパラメータの配列 */
39    var $objFormParam;
40
41
42    // }}}
43    // {{{ functions
44
45    /**
46     * Page を初期化する.
47     * @return void
48     */
49    function init() {
50        parent::init();
51        $masterData         = new SC_DB_MasterData_Ex();
52        $this->arrPref      = $masterData->getMasterData('mtb_pref');
53        $this->arrJob       = $masterData->getMasterData("mtb_job");
54        $this->arrReminder  = $masterData->getMasterData("mtb_reminder");
55
56        // 生年月日選択肢の取得
57        $objDate            = new SC_Date(START_BIRTH_YEAR, date("Y",strtotime("now")));
58        $this->arrYear      = $objDate->getYear('', 1950, '');
59        $this->arrMonth     = $objDate->getMonth(true);
60        $this->arrDay       = $objDate->getDay(true);
61
62        $this->httpCacheControl('nocache');
63
64        $this->isMobile     = Net_UserAgent_Mobile::isMobile();
65
66        // パラメータ管理クラス,パラメータ情報の初期化
67        $this->objFormParam = new SC_FormParam();
68        $this->lfInitParam();
69    }
70
71    /**
72     * Page のプロセス.
73     *
74     * @return void
75     */
76    function process() {
77        $this->action();
78        $this->sendResponse();
79    }
80
81    /* パラメータ情報の初期化 */
82    function lfInitParam() {
83
84        $this->objFormParam->addParam("お名前(姓)", 'name01', STEXT_LEN, "aKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" ,"MAX_LENGTH_CHECK"));
85        $this->objFormParam->addParam("お名前(名)", 'name02', STEXT_LEN, "aKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" , "MAX_LENGTH_CHECK"));
86        $this->objFormParam->addParam("お名前(フリガナ・姓)", 'kana01', STEXT_LEN, "CKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANA_CHECK"));
87        $this->objFormParam->addParam("お名前(フリガナ・名)", 'kana02', STEXT_LEN, "CKV", array("EXIST_CHECK", "NO_SPTAB", "SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANA_CHECK"));
88        $this->objFormParam->addParam("パスワード", 'password', STEXT_LEN, "a", array("EXIST_CHECK", "SPTAB_CHECK" ,"ALNUM_CHECK"));
89        $this->objFormParam->addParam("パスワード確認用の質問", "reminder", STEXT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
90        $this->objFormParam->addParam("パスワード確認用の質問の答え", "reminder_answer", STEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" , "MAX_LENGTH_CHECK"));
91        $this->objFormParam->addParam("郵便番号1", "zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK" ,"NUM_CHECK", "NUM_COUNT_CHECK"));
92        $this->objFormParam->addParam("郵便番号2", "zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "SPTAB_CHECK" ,"NUM_CHECK", "NUM_COUNT_CHECK"));
93        $this->objFormParam->addParam("都道府県", 'pref', INT_LEN, "n", array("EXIST_CHECK","NUM_CHECK"));
94        $this->objFormParam->addParam("住所1", "addr01", MTEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" ,"MAX_LENGTH_CHECK"));
95        $this->objFormParam->addParam("住所2", "addr02", MTEXT_LEN, "aKV", array("EXIST_CHECK","SPTAB_CHECK" ,"MAX_LENGTH_CHECK"));
96        $this->objFormParam->addParam("お電話番号1", 'tel01', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK" ));
97        $this->objFormParam->addParam("お電話番号2", 'tel02', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK" ));
98        $this->objFormParam->addParam("お電話番号3", 'tel03', TEL_ITEM_LEN, "n", array("EXIST_CHECK","SPTAB_CHECK" ));
99        $this->objFormParam->addParam("性別", "sex", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
100        $this->objFormParam->addParam("職業", "job", INT_LEN, "n", array("NUM_CHECK"));
101        $this->objFormParam->addParam("年", "year", INT_LEN, "n", array("MAX_LENGTH_CHECK"), "", false);
102        $this->objFormParam->addParam("月", "month", INT_LEN, "n", array("MAX_LENGTH_CHECK"), "", false);
103        $this->objFormParam->addParam("日", "day", INT_LEN, "n", array("MAX_LENGTH_CHECK"), "", false);
104        $this->objFormParam->addParam("メールマガジン", "mailmaga_flg", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK"));
105
106        if ($this->isMobile === false){
107            $this->objFormParam->addParam("FAX番号1", 'fax01', TEL_ITEM_LEN, "n", array("SPTAB_CHECK"));
108            $this->objFormParam->addParam("FAX番号2", 'fax02', TEL_ITEM_LEN, "n", array("SPTAB_CHECK"));
109            $this->objFormParam->addParam("FAX番号3", 'fax03', TEL_ITEM_LEN, "n", array("SPTAB_CHECK"));
110            $this->objFormParam->addParam("パスワード(確認)", 'password02', STEXT_LEN, "a", array("EXIST_CHECK", "SPTAB_CHECK" ,"ALNUM_CHECK"), "", false);
111            $this->objFormParam->addParam('メールアドレス', "email", MTEXT_LEN, "a", array("NO_SPTAB", "EXIST_CHECK", "EMAIL_CHECK", "SPTAB_CHECK" ,"EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
112            $this->objFormParam->addParam('メールアドレス(確認)', "email02", MTEXT_LEN, "a", array("NO_SPTAB", "EXIST_CHECK", "EMAIL_CHECK","SPTAB_CHECK" , "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"), "", false);
113        } else {
114            $this->objFormParam->addParam('メールアドレス', "email", MTEXT_LEN, "a", array("EXIST_CHECK", "EMAIL_CHECK", "NO_SPTAB" ,"EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK","MOBILE_EMAIL_CHECK"));
115        }
116    }
117
118    /**
119     * Page のプロセス
120     * @return void
121     */
122    function action() {
123        $this->lfPreMode();
124        $this->arrForm  = $this->objFormParam->getHashArray();
125
126        switch ($this->getMode()) {
127        case 'confirm':
128        //-- 確認
129            $this->arrErr = $this->lfErrorCheck();
130            // 入力エラーなし
131            if(empty($this->arrErr)) {
132                //パスワード表示
133                $this->passlen      = SC_Utils_Ex::sfPassLen(strlen($this->arrForm['password']));
134
135                $this->tpl_mainpage = 'entry/confirm.tpl';
136                $this->tpl_title    = '会員登録(確認ページ)';
137            }
138            break;
139        case 'complete':
140            //-- 会員登録と完了画面
141            $this->arrErr = $this->lfErrorCheck();
142            if(empty($this->arrErr)) {
143                $uniqid             = $this->lfRegistData();
144
145                $this->tpl_mainpage = 'entry/complete.tpl';
146                $this->tpl_title    = '会員登録(完了ページ)';
147
148                $this->lfSendMail($uniqid);
149
150                // 完了ページに移動させる。
151                SC_Response_Ex::sendRedirect('complete.php', array("ci" => $this->lfGetCustomerId($uniqid)));
152            }
153            break;
154        default:
155            break;
156        }
157
158        $this->transactionid = SC_Helper_Session_Ex::getToken();
159    }
160
161    /**
162     * デストラクタ.
163     *
164     * @return void
165     */
166    function destroy() {
167        parent::destroy();
168    }
169
170    // }}}
171    // {{{ protected functions
172
173
174    /**
175     * lfPreMode
176     *
177     * @access public
178     * @return void
179     */
180    function lfPreMode() {
181        // PC時は規約ページからの遷移でなければエラー画面へ遷移する
182        $this->lfCheckReferer();
183
184        // mobile用(戻るボタンでの遷移かどうかを判定)
185        if (!empty($_POST["return"])) {
186            $_POST["mode"] = "return";
187        }
188
189        //CSRF対策
190        $this->lfCheckCSRF();
191
192        $this->objFormParam->setParam($_POST);    // POST値の取得
193        $this->objFormParam->convParam();
194        $this->objFormParam->toLower('email');
195        $this->objFormParam->toLower('email02');
196    }
197
198
199    /**
200     * lfRegistData
201     *
202     * 会員情報の登録
203     *
204     * @access public
205     * @return void
206     */
207    function lfRegistData() {
208        $objQuery   = new SC_Query();
209        //-- 登録実行
210        $sqlval     = $this->lfMakeSqlVal();
211        $objQuery->begin();
212        SC_Helper_Customer_Ex::sfEditCustomerData($sqlval);
213        $objQuery->commit();
214
215        return $sqlval["secret_key"];
216    }
217
218
219    /**
220     * lfMakeSqlVal
221     *
222     * 会員登録に必要なsqlを作成する
223     *
224     * @access public
225     * @return void
226     */
227    function lfMakeSqlVal() {
228        $arrRet     = $this->objFormParam->getHashArray();
229        $sqlval     = $this->objFormParam->getDbArray();
230
231        // 登録データの作成
232        $sqlval['birth']  = SC_Utils_Ex::sfGetTimestamp($arrRet['year'], $arrRet['month'], $arrRet['day']);
233
234        // 仮会員 1 本会員 2
235        $sqlval["status"] = (CUSTOMER_CONFIRM_MAIL == true) ? "1" : "2";
236
237        /*
238          secret_keyは、テーブルで重複許可されていない場合があるので、
239                          本会員登録では利用されないがセットしておく。
240        */
241        $sqlval["secret_key"] = SC_Helper_Customer_Ex::sfGetUniqSecretKey();        // 会員登録キー
242
243        $CONF = SC_Helper_DB_Ex::sfGetBasisData();
244        $sqlval["point"] = $CONF["welcome_point"]; // 入会時ポイント
245
246        if ($this->isMobile === true) {
247            // 携帯メールアドレス
248            $sqlval['email_mobile']     = $sqlval['email'];
249            //PHONE_IDを取り出す
250            $sqlval['mobile_phone_id']  =  SC_MobileUserAgent::getId();
251        }
252
253        return $sqlval;
254    }
255
256
257    /**
258     * lfSendMail
259     *
260     * @access public
261     * @return void
262     */
263    function lfSendMail($uniqid){
264        // 完了メール送信
265        $arrRet         = $this->objFormParam->getHashArray();
266        $this->name01   = $arrRet['name01'];
267        $this->name02   = $arrRet['name02'];
268        $this->uniqid   = $uniqid;
269        $objMailText    = new SC_SiteView();
270        $objMailText->assignobj($this);
271
272        $objHelperMail  = new SC_Helper_Mail_Ex();
273        $objCustomer    = new SC_Customer();
274        $CONF           = SC_Helper_DB_Ex::sfGetBasisData();
275
276        // 仮会員が有効の場合
277        if(CUSTOMER_CONFIRM_MAIL == true) {
278            $subject = $objHelperMail->sfMakeSubject('会員登録のご確認');
279            $toCustomerMail = $objMailText->fetch("mail_templates/customer_mail.tpl");
280        } else {
281            $subject = $objHelperMail->sfMakeSubject('会員登録のご完了');
282            $toCustomerMail = $objMailText->fetch("mail_templates/customer_regist_mail.tpl");
283            // ログイン状態にする
284            $objCustomer->setLogin($arrRet["email"]);
285        }
286
287        $objMail = new SC_SendMail();
288        $objMail->setItem(
289                              ''                    // 宛先
290                            , $subject              // サブジェクト
291                            , $toCustomerMail       // 本文
292                            , $CONF["email03"]      // 配送元アドレス
293                            , $CONF["shop_name"]    // 配送元 名前
294                            , $CONF["email03"]      // reply_to
295                            , $CONF["email04"]      // return_path
296                            , $CONF["email04"]      // Errors_to
297                            , $CONF["email01"]      // Bcc
298        );
299        // 宛先の設定
300        $name = $arrRet["name01"] . $arrRet["name02"] ." 様";
301        $objMail->setTo($arrRet["email"], $name);
302        $objMail->sendMail();
303    }
304
305    /**
306     * lfErrorCheck
307     *
308     * 入力エラーチェック
309     *
310     * @param mixed $array
311     * @access public
312     * @return void
313     */
314    function lfErrorCheck($array) {
315
316        // 入力データを渡す。
317        $arrRet = $this->objFormParam->getHashArray();
318        $objErr = new SC_CheckError($arrRet);
319        $objErr->arrErr = $this->objFormParam->checkError();
320
321        $objErr->doFunc(array("お電話番号", "tel01", "tel02", "tel03"),array("TEL_CHECK"));
322        $objErr->doFunc(array("郵便番号", "zip01", "zip02"), array("ALL_EXIST_CHECK"));
323        $objErr->doFunc(array("生年月日", "year", "month", "day"), array("CHECK_BIRTHDAY"));
324        if ($this->isMobile === false){
325            $objErr->doFunc(array('パスワード', 'パスワード(確認)', "password", "password02") ,array("EQUAL_CHECK"));
326            $objErr->doFunc(array('メールアドレス', 'メールアドレス(確認)', "email", "email02") ,array("EQUAL_CHECK"));
327            $objErr->doFunc(array("FAX番号", "fax01", "fax02", "fax03") ,array("TEL_CHECK"));
328        }
329
330        // 現会員の判定 → 現会員もしくは仮登録中は、メアド一意が前提になってるので同じメアドで登録不可
331        $objErr->doFunc(array("メールアドレス", "email"), array("CHECK_REGIST_CUSTOMER_EMAIL"));
332
333        return $objErr->arrErr;
334    }
335
336    /**
337     * lfCheckReferer
338     *
339     * @access public
340     * @return void
341     */
342    function lfCheckReferer(){
343        /**
344         * 規約ページからの遷移でなければエラー画面へ遷移する
345         */
346        if ($this->isMobile === FALSE
347             && empty($_POST)
348             && !preg_match('/kiyaku.php/', basename($_SERVER['HTTP_REFERER']))
349            ) {
350            SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, "", true);
351        }
352    }
353
354
355    /**
356     * lfCheckCSRF
357     *
358     * @access public
359     * @return void
360     */
361    function lfCheckCSRF() {
362        if ($_SERVER["REQUEST_METHOD"] == "POST") {
363            if (!SC_Helper_Session_Ex::isValidToken()) {
364                SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, "", true);
365            }
366        }
367    }
368
369
370    /**
371     * lfGetCustomerId
372     *
373     * @param mixed $uniqid
374     * @access public
375     * @return void
376     */
377    function lfGetCustomerId($uniqid) {
378        $objQuery = new SC_Query();
379        return $objQuery->get("customer_id", "dtb_customer", "secret_key = ?", array($uniqid));
380    }
381}
Note: See TracBrowser for help on using the repository browser.