$pwd = addslashes(filter_input(INPUT_POST, 'pwdInput')); $customerMgr = new CustomerManager(); $customer = $customerMgr->getCustomerByIDPassword($userid, $pwd); $creditMgr = new CreditManager(); $productMgr = new ProductManager(); session_start(); //echo mysql_num_rows($resultSet); if ($customer !== []) { $form_data['success'] = true; $_SESSION["userid"] = $userid; if (isset($_COOKIE["sender_email"])) { $sender_email = $_COOKIE["sender_email"]; if ($sender_email !== $userid) { $has_received = $creditMgr->checkInvitationStatus($sender_email, $userid); if ($has_received === null) { $creditMgr->addCredit($sender_email, $userid); $customerMgr->updateCredit($userid, 10.0); setcookie('sender_email', '', time() - 1); $form_data['status'] = 'success'; $form_data['message'] = "Congratulations! You have got \$10 credits from your friend!"; } else { $form_data['status'] = 'fail'; $form_data['message'] = "You have already received credit from your friend!"; setcookie('sender_email', '', time() - 1); } } else { $form_data['status'] = 'fail'; $form_data['message'] = "Cyclic referral detected!"; setcookie('sender_email', '', time() - 1); } }
} if (isset($_GET['key'])) { $key = $_GET['key']; } $invitation_link = $customerMgr->getInvitationLink($email); $retrieved_key = substr($invitation_link, strpos($invitation_link, "=") + 1); if (md5($retrieved_key) === $key) { session_start(); $customerMgr->activateAccount($email); $_SESSION["userid"] = $email; $form_data['status'] = 'success'; $form_data['message'] = ""; //Add credit to the new signed-up account if there is credit sender information in session if (isset($_COOKIE["sender_email"])) { $sender_email = $_COOKIE["sender_email"]; $creditMgr->addCredit($sender_email, $email); $customerMgr->updateCredit($email, 10.0); $form_data['status'] = 'success'; $form_data['message'] = "Congratulations! You have got \$10 credits from your friend!"; setcookie('sender_email', '', time() - 1); } // Add cart item in temporary status into the cart of new signed-up account if (isset($_SESSION['temp_product_id_to_cart']) && !empty($_SESSION['temp_product_id_to_cart'])) { if ($productMgr->retrieveItemQtyInShoppingCart($userid, $_SESSION['temp_product_id_to_cart']) > 0) { $addedQty = $productMgr->retrieveItemQtyInShoppingCart($userid, $_SESSION['temp_product_id_to_cart']); $totalQty = $addedQty + $_SESSION['temp_product_qty_to_cart']; $productMgr->updateItemQty($userid, $_SESSION['temp_product_id_to_cart'], $totalQty); } else { $productMgr->addProductToShoppingCart($userid, $_SESSION['temp_product_id_to_cart'], $_SESSION['temp_product_qty_to_cart']); } unset($_SESSION['temp_product_id_to_cart']);
$receiver_email = null; $sender_email = $sender['customer_id']; if (!empty($_SESSION["userid"])) { #Situation 3: browser contains login information $receiver_email = $_SESSION["userid"]; if ($receiver_email == $sender_email) { #Situation 7: receiver and sender share same email. It means it's an illegal self-referral $status = 'fail'; $message = "Cyclic referral detected!"; header("Location: index.php?status={$status}&message={$message}"); exit; } $status = $creditMgr->checkInvitationStatus($sender_email, $receiver_email); if ($status == null) { #Situation 5: receiver has not accepted any credit from sender. Successfully receive credit and redirect to index $creditMgr->addCredit($sender_email, $receiver_email); $customerMgr->updateCredit($receiver_email, 10.0); $status = 'success'; $message = "Congratulations! You have got <br> \$10 credits from your friend!"; header("Location: index.php?status={$status}&message={$message}"); exit; } else { #Situation 6: receiver has already received credit from sender. Redirect to index and prompt error. $status = 'fail'; $message = "You have already received <br> credit from your friend!"; header("Location: index.php?status={$status}&message={$message}"); exit; } } else { #Situation 4: browser does NOT contain login information. We need to retain referral information for immediate registration $status = 'pending';