source: branches/version-2_13-dev/data/class/SC_Customer.php @ 22856

Revision 22856, 12.6 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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-2013 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/*  [名称] SC_Customer
25 *  [概要] 会員管理クラス
26 */
27class SC_Customer
28{
29    /** 会員情報 */
30    var $customer_data;
31
32    function getCustomerDataFromEmailPass($pass, $email, $mobile = false)
33    {
34        // 小文字に変換
35        $email = strtolower($email);
36        $sql_mobile = $mobile ? ' OR email_mobile = ?' : '';
37        $arrValues = array($email);
38        if ($mobile) {
39            $arrValues[] = $email;
40        }
41        // 本登録された会員のみ
42        $sql = 'SELECT * FROM dtb_customer WHERE (email = ?' . $sql_mobile . ') AND del_flg = 0 AND status = 2';
43        $objQuery =& SC_Query_Ex::getSingletonInstance();
44        $result = $objQuery->getAll($sql, $arrValues);
45        if (empty($result)) {
46            return false;
47        } else {
48            $data = $result[0];
49        }
50
51        // パスワードが合っていれば会員情報をcustomer_dataにセットしてtrueを返す
52        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt'])) {
53            $this->customer_data = $data;
54            $this->startSession();
55            return true;
56        }
57
58        return false;
59    }
60
61    /**
62     * 携帯端末IDが一致する会員が存在するかどうかをチェックする。
63     * FIXME
64     * @return boolean 該当する会員が存在する場合は true、それ以外の場合
65     *                 は false を返す。
66     */
67    function checkMobilePhoneId()
68    {
69        //docomo用にデータを取り出す。
70        if (SC_MobileUserAgent_Ex::getCarrier() == 'docomo') {
71            if ($_SESSION['mobile']['phone_id'] == '' && strlen($_SESSION['mobile']['phone_id']) == 0) {
72                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
73            }
74        }
75        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
76            return false;
77        }
78
79        // 携帯端末IDが一致し、本登録された会員を検索する。
80        $objQuery =& SC_Query_Ex::getSingletonInstance();
81        $exists = $objQuery->exists('dtb_customer', 'mobile_phone_id = ? AND del_flg = 0 AND status = 2', array($_SESSION['mobile']['phone_id']));
82
83        return $exists;
84    }
85
86    /**
87     * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。
88     * パスワードが合っている場合は会員情報を取得する。
89     *
90     * @param string $pass パスワード
91     * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、
92     *                 それ以外の場合は false を返す。
93     */
94    function getCustomerDataFromMobilePhoneIdPass($pass)
95    {
96        //docomo用にデータを取り出す。
97        if (SC_MobileUserAgent_Ex::getCarrier() == 'docomo') {
98            if ($_SESSION['mobile']['phone_id'] == '' && strlen($_SESSION['mobile']['phone_id']) == 0) {
99                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
100            }
101        }
102        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
103            return false;
104        }
105
106        // 携帯端末IDが一致し、本登録された会員を検索する。
107        $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
108        $objQuery =& SC_Query_Ex::getSingletonInstance();
109        @list($data) = $objQuery->getAll($sql, array($_SESSION['mobile']['phone_id']));
110
111        // パスワードが合っている場合は、会員情報をcustomer_dataに格納してtrueを返す。
112        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt'])) {
113            $this->customer_data = $data;
114            $this->startSession();
115            return true;
116        }
117
118        return false;
119    }
120
121    /**
122     * 携帯端末IDを登録する。
123     *
124     * @return void
125     */
126    function updateMobilePhoneId()
127    {
128        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
129            return;
130        }
131
132        if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) {
133            return;
134        }
135
136        $objQuery =& SC_Query_Ex::getSingletonInstance();
137        $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']);
138        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
139        $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
140
141        $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id'];
142    }
143
144    // パスワードを確認せずにログイン
145    function setLogin($email)
146    {
147        // 本登録された会員のみ
148        $sql = 'SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2';
149        $objQuery =& SC_Query_Ex::getSingletonInstance();
150        $result = $objQuery->getAll($sql, array($email, $email));
151        $data = isset($result[0]) ? $result[0] : '';
152        $this->customer_data = $data;
153        $this->startSession();
154    }
155
156    // セッション情報を最新の情報に更新する
157    function updateSession()
158    {
159        $sql = 'SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0';
160        $customer_id = $this->getValue('customer_id');
161        $objQuery =& SC_Query_Ex::getSingletonInstance();
162        $arrRet = $objQuery->getAll($sql, array($customer_id));
163        $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : '';
164        $_SESSION['customer'] = $this->customer_data;
165    }
166
167    // ログイン情報をセッションに登録し、ログに書き込む
168    function startSession()
169    {
170        $_SESSION['customer'] = $this->customer_data;
171        // セッション情報の保存
172        GC_Utils_Ex::gfPrintLog('access : user='.$this->customer_data['customer_id'] ."\t".'ip='. $this->getRemoteHost(), CUSTOMER_LOG_REALFILE, false);
173    }
174
175    // ログアウト $_SESSION['customer']を解放し、ログに書き込む
176    function EndSession()
177    {
178        // セッション情報破棄の前にcustomer_idを保存
179        $customer_id = $_SESSION['customer']['customer_id'];
180
181        // $_SESSION['customer']の解放
182        unset($_SESSION['customer']);
183        // セッションの配送情報を全て破棄する
184        SC_Helper_Purchase_Ex::unsetAllShippingTemp(true);
185        // トランザクショントークンの破棄
186        SC_Helper_Session_Ex::destroyToken();
187        $objSiteSess = new SC_SiteSession_Ex();
188        $objSiteSess->unsetUniqId();
189
190        // ログに記録する
191        $log = sprintf("logout : user=%d\tip=%s",
192            $customer_id, $this->getRemoteHost());
193        GC_Utils_Ex::gfPrintLog($log, CUSTOMER_LOG_REALFILE, false);
194    }
195
196    // ログインに成功しているか判定する。
197    function isLoginSuccess($dont_check_email_mobile = false)
198    {
199        // ログイン時のメールアドレスとDBのメールアドレスが一致している場合
200        if (isset($_SESSION['customer']['customer_id'])
201            && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])
202        ) {
203            $objQuery =& SC_Query_Ex::getSingletonInstance();
204            $email = $objQuery->get('email', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
205            if ($email == $_SESSION['customer']['email']) {
206                // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。
207                // ただし $dont_check_email_mobile が true の場合はチェックしない。
208                if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE && !$dont_check_email_mobile) {
209                    $email_mobile = $objQuery->get('email_mobile', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
210                    return isset($email_mobile);
211                }
212                return true;
213            }
214        }
215
216        return false;
217    }
218
219    // パラメーターの取得
220    function getValue($keyname)
221    {
222        // ポイントはリアルタイム表示
223        if ($keyname == 'point') {
224            $objQuery =& SC_Query_Ex::getSingletonInstance();
225            $point = $objQuery->get('point', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
226            $_SESSION['customer']['point'] = $point;
227            return $point;
228        } else {
229            return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : '';
230        }
231    }
232
233    // パラメーターのセット
234    function setValue($keyname, $val)
235    {
236        $_SESSION['customer'][$keyname] = $val;
237    }
238
239    // パラメーターがNULLかどうかの判定
240    function hasValue($keyname)
241    {
242        if (isset($_SESSION['customer'][$keyname])) {
243            return !SC_Utils_Ex::isBlank($_SESSION['customer'][$keyname]);
244        }
245
246        return false;
247    }
248
249    // 誕生日月であるかどうかの判定
250    function isBirthMonth()
251    {
252        if (isset($_SESSION['customer']['birth'])) {
253            $arrRet = preg_split('|[- :/]|', $_SESSION['customer']['birth']);
254            $birth_month = intval($arrRet[1]);
255            $now_month = intval(date('m'));
256
257            if ($birth_month == $now_month) {
258                return true;
259            }
260        }
261
262        return false;
263    }
264
265    /**
266     * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す.
267     *
268     * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR']
269     * を返す.
270     *
271     * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列
272     */
273    function getRemoteHost()
274    {
275        if (!empty($_SERVER['REMOTE_HOST'])) {
276            return $_SERVER['REMOTE_HOST'];
277        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
278            return $_SERVER['REMOTE_ADDR'];
279        } else {
280            return '';
281        }
282    }
283
284    //受注関連の会員情報を更新
285    function updateOrderSummary($customer_id)
286    {
287        $objQuery =& SC_Query_Ex::getSingletonInstance();
288        $arrOrderSummary =  $objQuery->getRow('SUM( payment_total) as buy_total, COUNT(order_id) as buy_times,MAX( create_date) as last_buy_date, MIN(create_date) as first_buy_date','dtb_order','customer_id = ? AND del_flg = 0 AND status <> ?',array($customer_id,ORDER_CANCEL));
289        $objQuery->update('dtb_customer',$arrOrderSummary,'customer_id = ?',array($customer_id));
290    }
291
292    /**
293     * ログインを実行する.
294     *
295     * ログインを実行し, 成功した場合はユーザー情報をセッションに格納し,
296     * true を返す.
297     * モバイル端末の場合は, 携帯端末IDを保存する.
298     * ログインに失敗した場合は, false を返す.
299     *
300     * @param string $login_email ログインメールアドレス
301     * @param string $login_pass ログインパスワード
302     * @return boolean ログインに成功した場合 true; 失敗した場合 false
303     */
304    function doLogin($login_email, $login_pass)
305    {
306        switch (SC_Display_Ex::detectDevice()) {
307            case DEVICE_TYPE_MOBILE:
308                if (!$this->getCustomerDataFromMobilePhoneIdPass($login_pass) &&
309                    !$this->getCustomerDataFromEmailPass($login_pass, $login_email, true)
310                ) {
311                    return false;
312                } else {
313                    $this->updateMobilePhoneId();
314                    return true;
315                }
316                break;
317
318            case DEVICE_TYPE_SMARTPHONE:
319            case DEVICE_TYPE_PC:
320            default:
321                if (!$this->getCustomerDataFromEmailPass($login_pass, $login_email)) {
322                    return false;
323                } else {
324                    return true;
325                }
326                break;
327        }
328    }
329}
Note: See TracBrowser for help on using the repository browser.