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

Revision 23605, 13.2 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

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