conn = $conn; } } else { if (class_exists($DB_class_name)){ //$DB_class_nameのインスタンスを作成する $this->conn = new SC_DbConn(); } } if ( is_object($this->conn) ) { // 正常にDBに接続できる if ( $email ){ // emailから顧客情報を取得する // $this->setCustomerDataFromEmail( $email ); } } else { echo "DB接続オブジェクトの生成に失敗しています"; exit; } if ( strlen($email) > 0 && strlen($pass) > 0 ){ $this->getCustomerDataFromEmailPass( $email, $pass ); } } function getCustomerDataFromEmailPass( $pass, $email, $mobile = false ) { // 小文字に変換 $email = strtolower($email); $sql_mobile = $mobile ? ' OR email_mobile = ?' : ''; $arrValues = array($email); if ($mobile) { $arrValues[] = $email; } // 本登録された会員のみ $sql = "SELECT * FROM dtb_customer WHERE (email = ?" . $sql_mobile . ") AND del_flg = 0 AND status = 2"; $result = $this->conn->getAll($sql, $arrValues); if (empty($result)) { return false; } else { $data = $result[0]; } // パスワードが合っていれば顧客情報をcustomer_dataにセットしてtrueを返す if ( sha1($pass . ":" . AUTH_MAGIC) == $data['password'] ){ $this->customer_data = $data; $this->startSession(); return true; } return false; } /** * 携帯端末IDが一致する会員が存在するかどうかをチェックする。 * * @return boolean 該当する会員が存在する場合は true、それ以外の場合 * は false を返す。 */ function checkMobilePhoneId() { //docomo用にデータを取り出す。 if(SC_MobileUserAgent::getCarrier() == 'docomo'){ if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); } if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { return false; } // 携帯端末IDが一致し、本登録された会員を検索する。 $sql = 'SELECT count(*) FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; $result = $this->conn->getOne($sql, array($_SESSION['mobile']['phone_id'])); return $result > 0; } /** * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。 * パスワードが合っている場合は顧客情報を取得する。 * * @param string $pass パスワード * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、 * それ以外の場合は false を返す。 */ function getCustomerDataFromMobilePhoneIdPass($pass) { //docomo用にデータを取り出す。 if(SC_MobileUserAgent::getCarrier() == 'docomo'){ if($_SESSION['mobile']['phone_id'] == "" && strlen($_SESSION['mobile']['phone_id']) == 0) $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent::getId(); } if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { return false; } // 携帯端末IDが一致し、本登録された会員を検索する。 $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2'; @list($data) = $this->conn->getAll($sql, array($_SESSION['mobile']['phone_id'])); // パスワードが合っている場合は、顧客情報をcustomer_dataに格納してtrueを返す。 if (sha1($pass . ':' . AUTH_MAGIC) == @$data['password']) { $this->customer_data = $data; $this->startSession(); return true; } return false; } /** * 携帯端末IDを登録する。 * * @return void */ function updateMobilePhoneId() { if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) { return; } if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) { return; } $objQuery = new SC_Query; $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']); $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id']; } /** * email から email_mobile へ携帯のメールアドレスをコピーする。 * * @return void */ function updateEmailMobile() { $objMobile = new SC_Helper_Mobile_Ex(); // すでに email_mobile に値が入っている場合は何もしない。 if ($this->customer_data['email_mobile'] != '') { return; } // email が携帯のメールアドレスではない場合は何もしない。 if (!$objMobile->gfIsMobileMailAddress($this->customer_data['email'])) { return; } // email から email_mobile へコピーする。 $objQuery = new SC_Query; $sqlval = array('email_mobile' => $this->customer_data['email']); $where = 'customer_id = ? AND del_flg = 0 AND status = 2'; $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id'])); $this->customer_data['email_mobile'] = $this->customer_data['email']; } // パスワードを確認せずにログイン function setLogin($email) { // 本登録された会員のみ $sql = "SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2"; $result = $this->conn->getAll($sql, array($email, $email)); $data = isset($result[0]) ? $result[0] : ""; $this->customer_data = $data; $this->startSession(); } // セッション情報を最新の情報に更新する function updateSession() { $sql = "SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0"; $customer_id = $this->getValue('customer_id'); $arrRet = $this->conn->getAll($sql, array($customer_id)); $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : ""; $_SESSION['customer'] = $this->customer_data; } // ログイン情報をセッションに登録し、ログに書き込む function startSession() { SC_Utils_Ex::sfDomainSessionStart(); $_SESSION['customer'] = $this->customer_data; // セッション情報の保存 GC_Utils_Ex::gfPrintLog("access : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); } // ログアウト $_SESSION['customer']を解放し、ログに書き込む function EndSession() { // $_SESSION['customer']の解放 unset($_SESSION['customer']); // ログに記録する GC_Utils_Ex::gfPrintLog("logout : user=".$this->customer_data['customer_id'] ."\t"."ip=". $this->getRemoteHost(), CUSTOMER_LOG_PATH ); } // ログインに成功しているか判定する。 function isLoginSuccess($dont_check_email_mobile = false) { // ログイン時のメールアドレスとDBのメールアドレスが一致している場合 if(isset($_SESSION['customer']['customer_id']) && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])) { $objQuery = new SC_Query(); $email = $objQuery->get("dtb_customer", "email", "customer_id = ?", array($_SESSION['customer']['customer_id'])); if($email == $_SESSION['customer']['email']) { // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。 // ただし $dont_check_email_mobile が true の場合はチェックしない。 if (defined('MOBILE_SITE') && !$dont_check_email_mobile) { $email_mobile = $objQuery->get("dtb_customer", "email_mobile", "customer_id = ?", array($_SESSION['customer']['customer_id'])); return isset($email_mobile); } return true; } } return false; } // パラメータの取得 function getValue($keyname) { return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : ""; } // パラメータのセット function setValue($keyname, $val) { $_SESSION['customer'][$keyname] = $val; } // パラメータがNULLかどうかの判定 function hasValue($keyname) { return isset($_SESSION['customer'][$keyname]); } // 誕生日月であるかどうかの判定 function isBirthMonth() { if (isset($_SESSION['customer']['birth'])) { $arrRet = split("[- :/]", $_SESSION['customer']['birth']); $birth_month = intval($arrRet[1]); $now_month = intval(date("m")); if($birth_month == $now_month) { return true; } } return false; } /** * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す. * * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR'] * を返す. * * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列 */ function getRemoteHost() { if (!empty($_SERVER['REMOTE_HOST'])) { return $_SERVER['REMOTE_HOST']; } elseif (!empty($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } else { return ""; } } } ?>