1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 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 | */ |
---|
27 | class SC_Customer { |
---|
28 | |
---|
29 | var $conn; |
---|
30 | var $email; |
---|
31 | var $customer_data; // 会員情報 |
---|
32 | |
---|
33 | function SC_Customer( $conn = '', $email = '', $pass = '' ) { |
---|
34 | // セッション開始 |
---|
35 | /* startSessionから移動 2005/11/04 中川 */ |
---|
36 | SC_Utils_Ex::sfDomainSessionStart(); |
---|
37 | |
---|
38 | // DB接続オブジェクト生成 |
---|
39 | $DB_class_name = "SC_DbConn"; |
---|
40 | if ( is_object($conn)){ |
---|
41 | if ( is_a($conn, $DB_class_name)){ |
---|
42 | // $connが$DB_class_nameのインスタンスである |
---|
43 | $this->conn = $conn; |
---|
44 | } |
---|
45 | } else { |
---|
46 | if (class_exists($DB_class_name)){ |
---|
47 | //$DB_class_nameのインスタンスを作成する |
---|
48 | $this->conn = new SC_DbConn(); |
---|
49 | } |
---|
50 | } |
---|
51 | |
---|
52 | if ( is_object($this->conn) ) { |
---|
53 | // 正常にDBに接続できる |
---|
54 | if ( $email ){ |
---|
55 | // emailから顧客情報を取得する |
---|
56 | // $this->setCustomerDataFromEmail( $email ); |
---|
57 | } |
---|
58 | } else { |
---|
59 | echo "DB接続オブジェクトの生成に失敗しています"; |
---|
60 | exit; |
---|
61 | } |
---|
62 | |
---|
63 | if ( strlen($email) > 0 && strlen($pass) > 0 ){ |
---|
64 | $this->getCustomerDataFromEmailPass( $email, $pass ); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) { |
---|
69 | // 小文字に変換 |
---|
70 | $email = strtolower($email); |
---|
71 | $sql_mobile = $mobile ? ' OR email_mobile = ?' : ''; |
---|
72 | $arrValues = array($email); |
---|
73 | if ($mobile) { |
---|
74 | $arrValues[] = $email; |
---|
75 | } |
---|
76 | // 本登録された会員のみ |
---|
77 | $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2"; |
---|
78 | $result = $this->conn->getAll($sql, $arrValues); |
---|
79 | if (empty($result)) { |
---|
80 | return false; |
---|
81 | } else { |
---|
82 | $data = $result[0]; |
---|
83 | } |
---|
84 | |
---|
85 | // パスワードが合っていれば顧客情報をcustomer_dataにセットしてtrueを返す |
---|
86 | if ( sha1($pass . ":" . AUTH_MAGIC) == $data['password'] ){ |
---|
87 | $this->customer_data = $data; |
---|
88 | $this->startSession(); |
---|
89 | return true; |
---|
90 | } |
---|
91 | return false; |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * 携帯端末IDが一致する会員が存在するかどうかをチェックする。 |
---|
96 | * |
---|
97 | * @return boolean 該当する会員が存在する場合は true、それ以外の場合 |
---|
98 | * は false を返す。 |
---|
99 | */ |
---|
100 | function checkMobilePhoneId() { |
---|
101 | //docomo用にデータを取り出す。 |
---|
102 | if(SC_MobileUserAgent::getCarrier() == 'docomo'){ |
---|
103 | if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) |
---|
104 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
105 | } |
---|
106 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
107 | return false; |
---|
108 | } |
---|
109 | |
---|
110 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
111 | $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
112 | $result = $this->conn->getOne($sql, array($_SESSION['mobile']['phone_id'])); |
---|
113 | return $result > 0; |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。 |
---|
118 | * パスワードが合っている場合は顧客情報を取得する。 |
---|
119 | * |
---|
120 | * @param string $pass パスワード |
---|
121 | * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、 |
---|
122 | * それ以外の場合は false を返す。 |
---|
123 | */ |
---|
124 | function getCustomerDataFromMobilePhoneIdPass($pass) { |
---|
125 | //docomo用にデータを取り出す。 |
---|
126 | if(SC_MobileUserAgent::getCarrier() == 'docomo'){ |
---|
127 | if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) |
---|
128 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
129 | } |
---|
130 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
131 | return false; |
---|
132 | } |
---|
133 | |
---|
134 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
135 | $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
136 | @list($data) = $this->conn->getAll($sql, array($_SESSION['mobile']['phone_id'])); |
---|
137 | |
---|
138 | // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。 |
---|
139 | if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) { |
---|
140 | $this->customer_data = $data; |
---|
141 | $this->startSession(); |
---|
142 | return true; |
---|
143 | } |
---|
144 | return false; |
---|
145 | } |
---|
146 | |
---|
147 | /** |
---|
148 | * 携帯端末IDを登録する。 |
---|
149 | * |
---|
150 | * @return void |
---|
151 | */ |
---|
152 | function updateMobilePhoneId() { |
---|
153 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
154 | return; |
---|
155 | } |
---|
156 | |
---|
157 | if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) { |
---|
158 | return; |
---|
159 | } |
---|
160 | |
---|
161 | $objQuery = new SC_Query; |
---|
162 | $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']); |
---|
163 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
164 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
165 | |
---|
166 | $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id']; |
---|
167 | } |
---|
168 | |
---|
169 | /** |
---|
170 | * email から email_mobile へ携帯のメールアドレスをコピーする。 |
---|
171 | * |
---|
172 | * @return void |
---|
173 | */ |
---|
174 | function updateEmailMobile() { |
---|
175 | |
---|
176 | $objMobile = new SC_Helper_Mobile_Ex(); |
---|
177 | // すでに email_mobile に値が入っている場合は何もしない。 |
---|
178 | if ($this->customer_data['email_mobile'] != '') { |
---|
179 | return; |
---|
180 | } |
---|
181 | |
---|
182 | // email が携帯のメールアドレスではない場合は何もしない。 |
---|
183 | if (!$objMobile->gfIsMobileMailAddress($this->customer_data['email'])) { |
---|
184 | return; |
---|
185 | } |
---|
186 | |
---|
187 | // email から email_mobile へコピーする。 |
---|
188 | $objQuery = new SC_Query; |
---|
189 | $sqlval = array('email_mobile' => $this->customer_data['email']); |
---|
190 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
191 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
192 | |
---|
193 | $this->customer_data['email_mobile'] = $this->customer_data['email']; |
---|
194 | } |
---|
195 | |
---|
196 | // パスワードを確認せずにログイン |
---|
197 | function setLogin($email) { |
---|
198 | // 本登録された会員のみ |
---|
199 | $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2"; |
---|
200 | $result = $this->conn->getAll($sql, array($email, $email)); |
---|
201 | $data = isset($result[0]) ? $result[0] : ""; |
---|
202 | $this->customer_data = $data; |
---|
203 | $this->startSession(); |
---|
204 | } |
---|
205 | |
---|
206 | // セッション情報を最新の情報に更新する |
---|
207 | function updateSession() { |
---|
208 | $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0"; |
---|
209 | $customer_id = $this->getValue('customer_id'); |
---|
210 | $arrRet = $this->conn->getAll($sql, array($customer_id)); |
---|
211 | $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : ""; |
---|
212 | $_SESSION['customer'] = $this->customer_data; |
---|
213 | } |
---|
214 | |
---|
215 | // ログイン情報をセッションに登録し、ログに書き込む |
---|
216 | function startSession() { |
---|
217 | SC_Utils_Ex::sfDomainSessionStart(); |
---|
218 | $_SESSION['customer'] = $this->customer_data; |
---|
219 | // セッション情報の保存 |
---|
220 | GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); |
---|
221 | } |
---|
222 | |
---|
223 | // ログアウト $_SESSION['customer']を解放し、ログに書き込む |
---|
224 | function EndSession() { |
---|
225 | // $_SESSION['customer']の解放 |
---|
226 | unset($_SESSION['customer']); |
---|
227 | // ログに記録する |
---|
228 | GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); |
---|
229 | } |
---|
230 | |
---|
231 | // ログインに成功しているか判定する。 |
---|
232 | function isLoginSuccess($dont_check_email_mobile = false) { |
---|
233 | // ログイン時のメールアドレスとDBのメールアドレスが一致している場合 |
---|
234 | if(isset($_SESSION['customer']['customer_id']) |
---|
235 | && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) { |
---|
236 | |
---|
237 | $objQuery = new SC_Query(); |
---|
238 | $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
239 | if($email == $_SESSION['customer']['email']) { |
---|
240 | // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。 |
---|
241 | // ただし $dont_check_email_mobile が true の場合はチェックしない。 |
---|
242 | if (defined('MOBILE_SITE') && !$dont_check_email_mobile) { |
---|
243 | $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
244 | return isset($email_mobile); |
---|
245 | } |
---|
246 | return true; |
---|
247 | } |
---|
248 | } |
---|
249 | return false; |
---|
250 | } |
---|
251 | |
---|
252 | // パラメータの取得 |
---|
253 | function getValue($keyname) { |
---|
254 | return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : ""; |
---|
255 | } |
---|
256 | |
---|
257 | // パラメータのセット |
---|
258 | function setValue($keyname, $val) { |
---|
259 | $_SESSION['customer'][$keyname] = $val; |
---|
260 | } |
---|
261 | |
---|
262 | // パラメータがNULLかどうかの判定 |
---|
263 | function hasValue($keyname) { |
---|
264 | return isset($_SESSION['customer'][$keyname]); |
---|
265 | } |
---|
266 | |
---|
267 | // 誕生日月であるかどうかの判定 |
---|
268 | function isBirthMonth() { |
---|
269 | if (isset($_SESSION['customer']['birth'])) { |
---|
270 | $arrRet = split("[- :/]", $_SESSION['customer']['birth']); |
---|
271 | $birth_month = intval($arrRet[1]); |
---|
272 | $now_month = intval(date("m")); |
---|
273 | |
---|
274 | if($birth_month == $now_month) { |
---|
275 | return true; |
---|
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 | 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 | ?> |
---|