source: branches/version-2_5-dev/data/class/SC_Customer.php @ 18770

Revision 18770, 9.6 KB checked in by nanasess, 14 years ago (diff)
  • SC_DbConn のインスタンスを直接使用している個所を SC_Query に変更(#565)
    • 削除予定の機能については未対応
  • SC_Customer で未使用の処理を削除
  • 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-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/*  [名称] SC_Customer
25 *  [概要] 会員管理クラス
26 */
27class SC_Customer {
28
29    var $customer_data;     // 会員情報
30
31    function SC_Customer() {
32    }
33
34    function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) {
35        // 小文字に変換
36        $email = strtolower($email);
37        $sql_mobile = $mobile ? ' OR email_mobile = ?' : '';
38        $arrValues = array($email);
39        if ($mobile) {
40            $arrValues[] = $email;
41        }
42        // 本登録された会員のみ
43        $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2";
44        $objQuery = new SC_Query();
45        $result = $objQuery->getAll($sql, $arrValues);
46        if (empty($result)) {
47            return false;
48        } else {
49            $data = $result[0];
50        }
51
52        // パスワードが合っていれば顧客情報をcustomer_dataにセットしてtrueを返す
53        if ( sha1($pass . ":" . AUTH_MAGIC) == $data['password'] ){
54            $this->customer_data = $data;
55            $this->startSession();
56            return true;
57        }
58        return false;
59    }
60
61    /**
62     * 携帯端末IDが一致する会員が存在するかどうかをチェックする。
63     *
64     * @return boolean 該当する会員が存在する場合は true、それ以外の場合
65     *                 は false を返す。
66     */
67    function checkMobilePhoneId() {
68        //docomo用にデータを取り出す。
69        if(SC_MobileUserAgent::getCarrier() == 'docomo'){
70            if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
71                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId();
72        }
73        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
74            return false;
75        }
76
77        // 携帯端末IDが一致し、本登録された会員を検索する。
78        $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
79        $objQuery = new SC_Query();
80        $result = $objQuery->count("dtb_customer", "mobile_phone_id = ? AND del_flg = 0 AND status = 2", array($_SESSION['mobile']['phone_id']));
81        return $result > 0;
82    }
83
84    /**
85     * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。
86     * パスワードが合っている場合は顧客情報を取得する。
87     *
88     * @param string $pass パスワード
89     * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、
90     *                 それ以外の場合は false を返す。
91     */
92    function getCustomerDataFromMobilePhoneIdPass($pass) {
93        //docomo用にデータを取り出す。
94        if(SC_MobileUserAgent::getCarrier() == 'docomo'){
95            if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0)
96                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId();
97        }
98        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
99            return false;
100        }
101
102        // 携帯端末IDが一致し、本登録された会員を検索する。
103        $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
104        $objQuery = new SC_Query();
105        @list($data) = $objQuery->getAll($sql, array($_SESSION['mobile']['phone_id']));
106
107        // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。
108        if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) {
109            $this->customer_data = $data;
110            $this->startSession();
111            return true;
112        }
113        return false;
114    }
115
116    /**
117     * 携帯端末IDを登録する。
118     *
119     * @return void
120     */
121    function updateMobilePhoneId() {
122        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
123            return;
124        }
125
126        if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) {
127            return;
128        }
129
130        $objQuery = new SC_Query;
131        $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']);
132        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
133        $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
134
135        $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id'];
136    }
137
138    // パスワードを確認せずにログイン
139    function setLogin($email) {
140        // 本登録された会員のみ
141        $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2";
142        $objQuery = new SC_Query();
143        $result = $objQuery->getAll($sql, array($email, $email));
144        $data = isset($result[0]) ? $result[0] : "";
145        $this->customer_data = $data;
146        $this->startSession();
147    }
148
149    // セッション情報を最新の情報に更新する
150    function updateSession() {
151        $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
152        $customer_id = $this->getValue('customer_id');
153        $objQuery = new SC_Query();
154        $arrRet = $objQuery->getAll($sql, array($customer_id));
155        $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : "";
156        $_SESSION['customer'] = $this->customer_data;
157    }
158
159    // ログイン情報をセッションに登録し、ログに書き込む
160    function startSession() {
161        SC_Utils_Ex::sfDomainSessionStart();
162        $_SESSION['customer'] = $this->customer_data;
163        // セッション情報の保存
164        GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH );
165    }
166
167    // ログアウト $_SESSION['customer']を解放し、ログに書き込む
168    function EndSession() {
169        // $_SESSION['customer']の解放
170        unset($_SESSION['customer']);
171        $objSiteSess = new SC_SiteSession();
172        $objSiteSess->unsetUniqId();
173        // ログに記録する
174        GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH );
175    }
176
177    // ログインに成功しているか判定する。
178    function isLoginSuccess($dont_check_email_mobile = false) {
179        // ログイン時のメールアドレスとDBのメールアドレスが一致している場合
180        if(isset($_SESSION['customer']['customer_id'])
181            && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) {
182
183            $objQuery = new SC_Query();
184            $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id']));
185            if($email == $_SESSION['customer']['email']) {
186                // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。
187                // ただし $dont_check_email_mobile が true の場合はチェックしない。
188                if (defined('MOBILE_SITE') && !$dont_check_email_mobile) {
189                    $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id']));
190                    return isset($email_mobile);
191                }
192                return true;
193            }
194        }
195        return false;
196    }
197
198    // パラメータの取得
199    function getValue($keyname) {
200        return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : "";
201    }
202
203    // パラメータのセット
204    function setValue($keyname, $val) {
205        $_SESSION['customer'][$keyname] = $val;
206    }
207
208    // パラメータがNULLかどうかの判定
209    function hasValue($keyname) {
210        return isset($_SESSION['customer'][$keyname]);
211    }
212
213    // 誕生日月であるかどうかの判定
214    function isBirthMonth() {
215        if (isset($_SESSION['customer']['birth'])) {
216            $arrRet = split("[- :/]", $_SESSION['customer']['birth']);
217            $birth_month = intval($arrRet[1]);
218            $now_month = intval(date("m"));
219
220            if($birth_month == $now_month) {
221                return true;
222            }
223        }
224        return false;
225    }
226
227    /**
228     * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す.
229     *
230     * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR']
231     * を返す.
232     *
233     * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列
234     */
235    function getRemoteHost() {
236
237        if (!empty($_SERVER['REMOTE_HOST'])) {
238            return $_SERVER['REMOTE_HOST'];
239        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
240            return $_SERVER['REMOTE_ADDR'];
241        } else {
242            return "";
243        }
244    }
245}
246?>
Note: See TracBrowser for help on using the repository browser.