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