source: branches/version-2_12-dev/data/class/SC_Customer.php @ 22206

Revision 22206, 12.5 KB checked in by kim, 11 years ago (diff)

#2003 copyrightを2013に更新

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