public function postAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { $customer = new Customer_Model_Customer(); try { if (!Zend_Validate::is($data['email'], 'EmailAddress')) { throw new Exception($this->_('Please enter a valid email address')); } $dummy = new Customer_Model_Customer(); $dummy->find(array('email' => $data['email'], "app_id" => $this->getApplication()->getId())); if ($dummy->getId()) { throw new Exception($this->_('We are sorry but this address is already used.')); } if (empty($data['show_in_social_gaming'])) { $data['show_in_social_gaming'] = 0; } if (empty($data['password'])) { throw new Exception($this->_('Please enter a password')); } $customer->setData($data)->setAppId($this->getApplication()->getId())->setPassword($data['password'])->save(); $this->getSession()->setCustomer($customer); $this->_sendNewAccountEmail($customer, $data['password']); $html = array('success' => 1, 'customer_id' => $customer->getId(), 'can_access_locked_features' => $customer->canAccessLockedFeatures()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function getCustomer() { if (is_null($this->_customer)) { $customer = new Customer_Model_Customer(); $this->_customer = $customer->find($this->getCustomerId()); } return $this->_customer; }
public function getEmployeesSummary($card_id, $start_at, $end_at) { $datas = $this->getTable()->getEmployeesSummary($card_id, $start_at, $end_at); $return = array(); foreach ($datas as $data) { if (!isset($return[$data['employee_id']]['count'])) { $return[$data['employee_id']] = array('name' => $data['name'], 'count' => 0, 'customer_ids' => array()); } $customer = new Customer_Model_Customer(); $customer->find($data['customer_id'])->setCountPoints($data['count']); $return[$data['employee_id']]['count'] += $data['count']; $return[$data['employee_id']]['customers'][$data['customer_id']] = $customer; } return $return; }
public function postAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { $customer = $this->getSession()->getCustomer(); try { $clearCache = false; if (!$customer->getId()) { throw new Exception($this->_("An error occurred while saving. Please try again later.")); } if (!Zend_Validate::is($data['email'], 'EmailAddress')) { throw new Exception($this->_('Please enter a valid email address')); } $dummy = new Customer_Model_Customer(); $dummy->find(array('email' => $data['email'], "app_id" => $this->getApplication()->getId())); if ($dummy->getId() and $dummy->getId() != $customer->getId()) { throw new Exception($this->_('We are sorry but this address is already used.')); } if (empty($data['show_in_social_gaming'])) { $data['show_in_social_gaming'] = 0; } if ($data['show_in_social_gaming'] != $customer->getShowInSocialGaming()) { $clearCache = true; } if (isset($data['id'])) { unset($data['id']); } if (isset($data['customer_id'])) { unset($data['customer_id']); } $password = ""; if (!empty($data['password'])) { if (empty($data['old_password']) or !empty($data['old_password']) and !$customer->isSamePassword($data['old_password'])) { throw new Exception($this->_("The old password does not match the entered password.")); } $password = $data['password']; } $customer->setData($data); if (!empty($password)) { $customer->setPassword($password); } $customer->save(); $html = array("success" => 1, "message" => $this->_("Info successfully saved"), "clearCache" => $clearCache); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function postAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { if (empty($data['email'])) { throw new Exception($this->_('Please enter your email address')); } if (!Zend_Validate::is($data['email'], 'EmailAddress')) { throw new Exception($this->_('Please enter a valid email address')); } $customer = new Customer_Model_Customer(); $customer->find(array('email' => $data['email'], "app_id" => $this->getApplication()->getId())); if (!$customer->getId()) { throw new Exception("Your email address does not exist"); } $admin_email = null; $password = Core_Model_Lib_String::generate(8); $contact = new Contact_Model_Contact(); $contact_page = $this->getApplication()->getPage('contact'); if ($contact_page->getId()) { $contact->find($contact_page->getId(), 'value_id'); $admin_email = $contact->getEmail(); } $customer->setPassword($password)->save(); $sender = 'no-reply@' . Core_Model_Lib_String::format($this->getApplication()->getName(), true) . '.com'; $layout = $this->getLayout()->loadEmail('customer', 'forgot_password'); $layout->getPartial('content_email')->setCustomer($customer)->setPassword($password)->setAdminEmail($admin_email)->setApp($this->getApplication()->getName()); $content = $layout->render(); $mail = new Zend_Mail('UTF-8'); $mail->setBodyHtml($content); $mail->setFrom($sender, $this->getApplication()->getName()); $mail->addTo($customer->getEmail(), $customer->getName()); $mail->setSubject($this->_('%s - Your new password', $this->getApplication()->getName())); $mail->send(); $html = array("success" => 1, "message" => $this->_("Your new password has been sent to the entered email address")); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } return $this; }
public function __construct($params) { $customer = new Customer_Model_Customer(); $customer->find($params['id']); $this->setObject($customer); }
public function savepostAction() { if ($datas = $this->getRequest()->getPost()) { if (!($customer = $this->getSession()->getCustomer())) { $customer = new Customer_Model_Customer(); } $isNew = !$customer->getId(); $isMobile = APPLICATION_TYPE == 'mobile'; try { if (!Zend_Validate::is($datas['email'], 'EmailAddress')) { throw new Exception($this->_('Please enter a valid email address')); } $dummy = new Customer_Model_Customer(); $dummy->find($datas['email'], 'email'); if ($isNew and $dummy->getId()) { throw new Exception($this->_('We are sorry but this address is already used.')); } if (!empty($datas['social_datas'])) { $social_ids = array(); foreach ($datas['social_datas'] as $type => $data) { if ($customer->findBySocialId($data['id'], $type)->getId()) { throw new Exception($this->_('We are sorry but the %s account is already linked to one of our customers', ucfirst($type))); } $social_ids[$type] = array('id' => $data['id']); } } $password = $customer->getPassword(); if (empty($datas['show_in_social_gaming'])) { $datas['show_in_social_gaming'] = 0; } $customer->setData($datas); $customer->setData('password', $password); if (isset($datas['id']) and $datas['id'] != $this->getSession()->getCustomer()->getId()) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } $formated_name = Core_Model_Lib_String::format($customer->getName(), true); $base_logo_path = $customer->getBaseImagePath() . '/' . $formated_name; if ($customer->getSocialPicture()) { $social_image = @file_get_contents($customer->getSocialPicture()); if ($social_image) { if (!is_dir($customer->getBaseImagePath())) { mkdir($customer->getBaseImagePath(), 0777); } $image_name = uniqid() . '.jpg'; $image = fopen($customer->getBaseImagePath() . '/' . $image_name, 'w'); fputs($image, $social_image); fclose($image); $customer->setImage('/' . $formated_name . '/' . $image_name); } else { $this->getSession()->addError($this->_('An error occurred while saving your picture. Please try againg later.')); } } if (empty($datas['password']) and $isNew) { throw new Exception($this->_('Please enter a password')); } if (!$isMobile and $datas['password'] != $datas['confirm_password']) { throw new Exception($this->_('Your password does not match the entered password.')); } if ($isNew and !$isMobile and $datas['email'] != $datas['confirm_email']) { throw new Exception($this->_("The old email address does not match the entered email address.")); } if (!$isNew and !empty($datas['old_password']) and !$customer->isSamePassword($datas['old_password'])) { throw new Exception($this->_("The old password does not match the entered password.")); } if (!empty($datas['password'])) { $customer->setPassword($datas['password']); } if (!empty($social_ids)) { $customer->setSocialDatas($social_ids); } $customer->save(); $this->getSession()->setCustomer($customer); if ($isNew) { $this->_sendNewAccountEmail($customer, $datas['password']); } if (!$isMobile) { $this->getSession()->addSuccess($this->_('Your account has been successfully saved')); // Retour des données (redirection vers la page en cours) $referer = !empty($datas['referer']) ? $datas['referer'] : $this->getRequest()->getHeader('referer'); $this->_redirect($referer); return $this; } foreach ($this->getRequest()->getParam('add_to_session', array()) as $key => $value) { $this->getSession()->{$key} = $value; } $html = array('success' => 1, 'customer_id' => $customer->getId()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function deleteAction() { if ($customer_id = $this->getRequest()->getPost('customer_id')) { try { $customer = new Customer_Model_Customer(); $customer->find($customer_id); if (!$customer->getId() || $customer->getAppId() != $this->getApplication()->getId()) { throw new Exception($this->_("An error occurred while saving. Please try again later.")); } $customer_id = $customer->getId(); $customer->delete(); $html = array("success" => 1, "customer_id" => $customer_id); } catch (Exception $e) { $html = array('message' => $e->getMessage(), 'message_button' => 1, 'message_loader' => 1); } $this->getResponse()->setBody(Zend_Json::encode($html))->sendResponse(); die; } }
public function loginwithfacebookAction() { if ($access_token = $this->getRequest()->getParam('token')) { try { // Reset session $this->getSession()->resetInstance(); // Fetch data from Facebook $graph_url = "https://graph.facebook.com/me?fields=id,name,email,first_name,last_name&access_token=" . $access_token; $user = json_decode(file_get_contents($graph_url)); if (!$user instanceof stdClass or !$user->id) { throw new Exception($this->_('An error occurred while connecting to your Facebook account. Please try again later')); } // Retrieve the user_id $user_id = $user->id; // Retrieve the current app ID $app_id = $this->getApplication()->getId(); // Load the customer from the user_id $customer = new Customer_Model_Customer(); $customer->findBySocialId($user_id, 'facebook', $app_id); // If the customer doesn't exist if (!$customer->getId()) { // Load the customer based on the email address in order to link the 2 accounts together if ($user->email) { $customer->find(array("email" => $user->email, "app_id" => $app_id)); } // If the email doesn't exist, create the account if (!$customer->getId()) { // Préparation des données du client $customer->setData(array("app_id" => $app_id, "firstname" => $user->first_name, "lastname" => $user->last_name, "email" => $user->email)); // Add a default password $customer->setPassword(uniqid()); // Retrieve its picture from Facebook $social_image = @file_get_contents("http://graph.facebook.com/{$user_id}/picture?type=large"); if ($social_image) { $formated_name = Core_Model_Lib_String::format($customer->getName(), true); $image_path = $customer->getBaseImagePath() . '/' . $formated_name; // Create customer's folder if (!is_dir($customer->getBaseImagePath())) { mkdir($image_path, 0777); } // Store the picture on the server $image_name = uniqid() . '.jpg'; $image = fopen($image_path . '/' . $image_name, 'w'); fputs($image, $social_image); fclose($image); // Resize the image Thumbnailer_CreateThumb::createThumbnail($image_path . '/' . $image_name, $image_path . '/' . $image_name, 150, 150, 'jpg', true); // Set the image to the customer $customer->setImage('/' . $formated_name . '/' . $image_name); } } } // Set the social data to the customer $customer->setSocialData('facebook', array('id' => $user_id, 'datas' => $access_token)); // Save the customer $customer->save(); // Log-in the customer $this->getSession()->setCustomer($customer); $html = array('success' => 1, 'customer_id' => $customer->getId(), 'can_access_locked_features' => $customer->canAccessLockedFeatures()); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }