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

Revision 19729, 9.5 KB checked in by Seasoft, 13 years ago (diff)

#855(SC_Query の #select, #getRow, #getCol, #get, #min, #max の引数順を統一する)

  • SC_Query#get を改訂
  • 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        $_SESSION['customer'] = $this->customer_data;
162        // セッション情報の保存
163        GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH );
164    }
165
166    // ログアウト $_SESSION['customer']を解放し、ログに書き込む
167    function EndSession() {
168        // $_SESSION['customer']の解放
169        unset($_SESSION['customer']);
170        $objSiteSess = new SC_SiteSession();
171        $objSiteSess->unsetUniqId();
172        // ログに記録する
173        GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH );
174    }
175
176    // ログインに成功しているか判定する。
177    function isLoginSuccess($dont_check_email_mobile = false) {
178        // ログイン時のメールアドレスとDBのメールアドレスが一致している場合
179        if(isset($_SESSION['customer']['customer_id'])
180            && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) {
181
182            $objQuery = new SC_Query();
183            $email = $objQuery->get("email", "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id']));
184            if($email == $_SESSION['customer']['email']) {
185                // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。
186                // ただし $dont_check_email_mobile が true の場合はチェックしない。
187                if (defined('MOBILE_SITE') && !$dont_check_email_mobile) {
188                    $email_mobile = $objQuery->get("email_mobile", "dtb_customer", "customer_id = ?", array($_SESSION['customer']['customer_id']));
189                    return isset($email_mobile);
190                }
191                return true;
192            }
193        }
194        return false;
195    }
196
197    // パラメータの取得
198    function getValue($keyname) {
199        return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : "";
200    }
201
202    // パラメータのセット
203    function setValue($keyname, $val) {
204        $_SESSION['customer'][$keyname] = $val;
205    }
206
207    // パラメータがNULLかどうかの判定
208    function hasValue($keyname) {
209        return isset($_SESSION['customer'][$keyname]);
210    }
211
212    // 誕生日月であるかどうかの判定
213    function isBirthMonth() {
214        if (isset($_SESSION['customer']['birth'])) {
215            $arrRet = split("[- :/]", $_SESSION['customer']['birth']);
216            $birth_month = intval($arrRet[1]);
217            $now_month = intval(date("m"));
218
219            if($birth_month == $now_month) {
220                return true;
221            }
222        }
223        return false;
224    }
225
226    /**
227     * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す.
228     *
229     * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR']
230     * を返す.
231     *
232     * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列
233     */
234    function getRemoteHost() {
235
236        if (!empty($_SERVER['REMOTE_HOST'])) {
237            return $_SERVER['REMOTE_HOST'];
238        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
239            return $_SERVER['REMOTE_ADDR'];
240        } else {
241            return "";
242        }
243    }
244}
245?>
Note: See TracBrowser for help on using the repository browser.