| 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 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
| 104 | } |
---|
| 105 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
| 106 | return false; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
| 110 | $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
| 111 | $result = $this->conn->getOne($sql, array($_SESSION['mobile']['phone_id'])); |
---|
| 112 | return $result > 0; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。 |
---|
| 117 | * パスワードが合っている場合は顧客情報を取得する。 |
---|
| 118 | * |
---|
| 119 | * @param string $pass パスワード |
---|
| 120 | * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、 |
---|
| 121 | * それ以外の場合は false を返す。 |
---|
| 122 | */ |
---|
| 123 | function getCustomerDataFromMobilePhoneIdPass($pass) { |
---|
| 124 | //docomo用にデータを取り出す。 |
---|
| 125 | if(SC_MobileUserAgent::getCarrier() == 'docomo'){ |
---|
| 126 | if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) |
---|
| 127 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
| 128 | } |
---|
| 129 | if(SC_MobileUserAgent::getCarrier() == 'docomo'){ |
---|
| 130 | $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); |
---|
| 131 | } |
---|
| 132 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
| 133 | return false; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // 携帯端末IDが一致し、本登録された会員を検索する。 |
---|
| 137 | $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; |
---|
| 138 | @list($data) = $this->conn->getAll($sql, array($_SESSION['mobile']['phone_id'])); |
---|
| 139 | |
---|
| 140 | // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。 |
---|
| 141 | if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) { |
---|
| 142 | $this->customer_data = $data; |
---|
| 143 | $this->startSession(); |
---|
| 144 | return true; |
---|
| 145 | } |
---|
| 146 | return false; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | /** |
---|
| 150 | * 携帯端末IDを登録する。 |
---|
| 151 | * |
---|
| 152 | * @return void |
---|
| 153 | */ |
---|
| 154 | function updateMobilePhoneId() { |
---|
| 155 | if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { |
---|
| 156 | return; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) { |
---|
| 160 | return; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | $objQuery = new SC_Query; |
---|
| 164 | $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']); |
---|
| 165 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
| 166 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
| 167 | |
---|
| 168 | $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id']; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | /** |
---|
| 172 | * email から email_mobile へ携帯のメールアドレスをコピーする。 |
---|
| 173 | * |
---|
| 174 | * @return void |
---|
| 175 | */ |
---|
| 176 | function updateEmailMobile() { |
---|
| 177 | |
---|
| 178 | $objMobile = new SC_Helper_Mobile_Ex(); |
---|
| 179 | // すでに email_mobile に値が入っている場合は何もしない。 |
---|
| 180 | if ($this->customer_data['email_mobile'] != '') { |
---|
| 181 | return; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | // email が携帯のメールアドレスではない場合は何もしない。 |
---|
| 185 | if (!$objMobile->gfIsMobileMailAddress($this->customer_data['email'])) { |
---|
| 186 | return; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | // email から email_mobile へコピーする。 |
---|
| 190 | $objQuery = new SC_Query; |
---|
| 191 | $sqlval = array('email_mobile' => $this->customer_data['email']); |
---|
| 192 | $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; |
---|
| 193 | $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); |
---|
| 194 | |
---|
| 195 | $this->customer_data['email_mobile'] = $this->customer_data['email']; |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | // パスワードを確認せずにログイン |
---|
| 199 | function setLogin($email) { |
---|
| 200 | // 本登録された会員のみ |
---|
| 201 | $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2"; |
---|
| 202 | $result = $this->conn->getAll($sql, array($email, $email)); |
---|
| 203 | $data = isset($result[0]) ? $result[0] : ""; |
---|
| 204 | $this->customer_data = $data; |
---|
| 205 | $this->startSession(); |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | // セッション情報を最新の情報に更新する |
---|
| 209 | function updateSession() { |
---|
| 210 | $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0"; |
---|
| 211 | $customer_id = $this->getValue('customer_id'); |
---|
| 212 | $arrRet = $this->conn->getAll($sql, array($customer_id)); |
---|
| 213 | $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : ""; |
---|
| 214 | $_SESSION['customer'] = $this->customer_data; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | // ログイン情報をセッションに登録し、ログに書き込む |
---|
| 218 | function startSession() { |
---|
| 219 | SC_Utils_Ex::sfDomainSessionStart(); |
---|
| 220 | $_SESSION['customer'] = $this->customer_data; |
---|
| 221 | // セッション情報の保存 |
---|
| 222 | GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | // ログアウト $_SESSION['customer']を解放し、ログに書き込む |
---|
| 226 | function EndSession() { |
---|
| 227 | // $_SESSION['customer']の解放 |
---|
| 228 | unset($_SESSION['customer']); |
---|
| 229 | // ログに記録する |
---|
| 230 | GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | // ログインに成功しているか判定する。 |
---|
| 234 | function isLoginSuccess($dont_check_email_mobile = false) { |
---|
| 235 | // ログイン時のメールアドレスとDBのメールアドレスが一致している場合 |
---|
| 236 | if(isset($_SESSION['customer']['customer_id']) |
---|
| 237 | && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) { |
---|
| 238 | |
---|
| 239 | $objQuery = new SC_Query(); |
---|
| 240 | $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
| 241 | if($email == $_SESSION['customer']['email']) { |
---|
| 242 | // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。 |
---|
| 243 | // ただし $dont_check_email_mobile が true の場合はチェックしない。 |
---|
| 244 | if (defined('MOBILE_SITE') && !$dont_check_email_mobile) { |
---|
| 245 | $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id'])); |
---|
| 246 | return isset($email_mobile); |
---|
| 247 | } |
---|
| 248 | return true; |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | return false; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | // パラメータの取得 |
---|
| 255 | function getValue($keyname) { |
---|
| 256 | return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : ""; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | // パラメータのセット |
---|
| 260 | function setValue($keyname, $val) { |
---|
| 261 | $_SESSION['customer'][$keyname] = $val; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | // パラメータがNULLかどうかの判定 |
---|
| 265 | function hasValue($keyname) { |
---|
| 266 | return isset($_SESSION['customer'][$keyname]); |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | // 誕生日月であるかどうかの判定 |
---|
| 270 | function isBirthMonth() { |
---|
| 271 | if (isset($_SESSION['customer']['birth'])) { |
---|
| 272 | $arrRet = split("[- :/]", $_SESSION['customer']['birth']); |
---|
| 273 | $birth_month = intval($arrRet[1]); |
---|
| 274 | $now_month = intval(date("m")); |
---|
| 275 | |
---|
| 276 | if($birth_month == $now_month) { |
---|
| 277 | return true; |
---|
| 278 | } |
---|
| 279 | } |
---|
| 280 | return false; |
---|
| 281 | } |
---|
| 282 | |
---|
| 283 | /** |
---|
| 284 | * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す. |
---|
| 285 | * |
---|
| 286 | * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR'] |
---|
| 287 | * を返す. |
---|
| 288 | * |
---|
| 289 | * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列 |
---|
| 290 | */ |
---|
| 291 | function getRemoteHost() { |
---|
| 292 | |
---|
| 293 | if (!empty($_SERVER['REMOTE_HOST'])) { |
---|
| 294 | return $_SERVER['REMOTE_HOST']; |
---|
| 295 | } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
---|
| 296 | return $_SERVER['REMOTE_ADDR']; |
---|
| 297 | } else { |
---|
| 298 | return ""; |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | } |
---|
| 302 | ?> |
---|