public function setupJson($source = false) { $request = Ajde::app()->getRequest(); // Init vars $name = null; $email = null; $address = null; $zipcode = null; $city = null; $region = null; $country = null; $shipmentMethod = null; $comment = null; if ($source === false) { // Read request $name = $request->getPostParam('name', false); $email = $request->getPostParam('email', false); $address = $request->getPostParam('shipment_address', false); $zipcode = $request->getPostParam('shipment_zipcode', false); $city = $request->getPostParam('shipment_city', false); $region = $request->getPostParam('shipment_region', false); $country = $request->getPostParam('shipment_country', false); $shipmentMethod = $request->getPostParam('shipment_method', false); $comment = $request->getPostParam('comment', false); } else { if ($source instanceof Ajde_User) { // Read user $name = $source->fullname; $email = $source->email; $address = $source->address; $zipcode = $source->zipcode; $city = $source->city; $region = $source->region; $country = $source->country; $shipmentMethod = false; $comment = false; } } // Return when fields are not complete if ($source === false) { if (empty($name) || empty($email) || empty($address) || empty($zipcode) || empty($city) || empty($country)) { return ['success' => false, 'message' => trans('Not all your details are filled out')]; } if (Ajde_Component_String::validEmail($email) === false) { return ['success' => false, 'message' => trans('Please provide a valid e-mail address')]; } if (empty($shipmentMethod)) { return ['success' => false, 'message' => trans('Please choose a shipment method')]; } } // Check for current transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); if ($session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction'))) { // Edit existing transaction $method = 'save'; } else { // Insert new transaction $method = 'insert'; } // Update transaction info $transaction->name = $name; $transaction->email = $email; $transaction->shipment_address = $address; $transaction->shipment_zipcode = $zipcode; $transaction->shipment_city = $city; $transaction->shipment_region = $region; $transaction->shipment_country = $country; $transaction->shipment_method = $shipmentMethod; $transaction->comment = $comment; // Save info to user if ($user = $this->getLoggedInUser()) { if ($request->hasPostParam('save_details', false)) { $user->address = $address; $user->zipcode = $zipcode; $user->city = $city; $user->region = $region; $user->country = $country; $user->save(); $user->login(); } $transaction->user = $user->getPK(); } // Update shipping total $shipping = new ShippingModel($transaction); $transaction->shipment_cost = 0; if (!empty($shipmentMethod) && $shipping->isAvailable($shipmentMethod)) { $transaction->shipment_cost = $shipping->getMethod($shipmentMethod)->getTotal(); } // Insert new transaction if ($method === 'insert') { if ($transaction->insert()) { $this->updateFromCart($transaction); $session = new Ajde_Session('AC.Shop'); $session->set('currentTransaction', $transaction->getPK()); if (!$transaction->shipment_itemsqty > 0) { return ['success' => false, 'message' => trans('No items added to current order')]; } return ['success' => true]; } return ['success' => false, 'message' => trans('Something went wrong')]; } $transaction->payment_amount = $transaction->shipment_itemstotal + $transaction->shipment_cost; // Update current transaction if ($transaction->save()) { if (!$transaction->shipment_itemsqty > 0) { return ['success' => false, 'message' => trans('No items added to current transaction')]; } return ['success' => true]; } // Everything else failed return ['success' => false, 'message' => trans('Something went wrong')]; }
public function registerJson() { $user = new UserModel(); $returnto = Ajde::app()->getRequest()->getPostParam('returnto', false); $username = Ajde::app()->getRequest()->getPostParam($user->usernameField); $password = Ajde::app()->getRequest()->getPostParam('password'); $passwordCheck = Ajde::app()->getRequest()->getPostParam('passwordCheck'); $email = Ajde::app()->getRequest()->getPostParam('email', false); $fullname = Ajde::app()->getRequest()->getPostParam('fullname', false); $return = array(false); $shadowUser = new UserModel(); if (empty($username) || empty($password)) { $return = array('success' => false, 'message' => __("Please provide " . $user->usernameField . " and password")); } else { if ($shadowUser->loadByField($shadowUser->usernameField, $username)) { $return = array('success' => false, 'message' => __(ucfirst($user->usernameField) . " already exist")); } else { if ($password !== $passwordCheck) { $return = array('success' => false, 'message' => __("Passwords do not match")); } else { if (empty($email)) { $return = array('success' => false, 'message' => __("Please provide an e-mail address")); } else { if (Ajde_Component_String::validEmail($email) === false) { $return = array('success' => false, 'message' => __('Please provide a valid e-mail address')); } else { if ($shadowUser->loadByField('email', $email)) { $return = array('success' => false, 'message' => __("A user with this e-mail address already exist")); } else { if (empty($fullname)) { $return = array('success' => false, 'message' => __("Please provide a full name")); } else { $user->set('email', $email); $user->set('fullname', $fullname); if ($user->add($username, $password)) { $user->login(); Ajde_Session_Flash::alert(sprintf(__('Welcome %s, you are now logged in.'), $fullname)); $return = array('success' => true, 'returnto' => $returnto); } else { $return = array('success' => false, 'message' => __("Something went wrong")); } } } } } } } } return $return; }
public function registerJson() { $user = new UserModel(); $returnto = Ajde::app()->getRequest()->getPostParam('returnto', false); $username = Ajde::app()->getRequest()->getPostParam($user->usernameField); $password = Ajde::app()->getRequest()->getPostParam('password', ''); $passwordCheck = Ajde::app()->getRequest()->getPostParam('passwordCheck', ''); $providername = Ajde::app()->getRequest()->getPostParam('provider', false); $email = Ajde::app()->getRequest()->getPostParam('email', false); $fullname = Ajde::app()->getRequest()->getPostParam('fullname', false); $return = [false]; $shadowUser = new UserModel(); $provider = false; if ($providername) { $sso = config('user.sso.providers'); if (!in_array($providername, $sso)) { Ajde_Http_Response::redirectNotFound(); } $classname = 'Ajde_User_Sso_' . ucfirst($providername); /* @var $provider Ajde_User_SSO_Interface */ $provider = new $classname(); } if (empty($username)) { $return = ['success' => false, 'message' => trans('Please provide a ' . $user->usernameField . '')]; } else { if (!$provider && empty($password)) { $return = ['success' => false, 'message' => trans('Please provide a password')]; } else { if ($shadowUser->loadByField($shadowUser->usernameField, $username)) { $return = ['success' => false, 'message' => trans(ucfirst($user->usernameField) . ' already exist')]; } else { if (!$provider && $password !== $passwordCheck) { $return = ['success' => false, 'message' => trans('Passwords do not match')]; } else { if (empty($email)) { $return = ['success' => false, 'message' => trans('Please provide an e-mail address')]; } else { if (Ajde_Component_String::validEmail($email) === false) { $return = ['success' => false, 'message' => trans('Please provide a valid e-mail address')]; } else { if ($shadowUser->loadByField('email', $email)) { $return = ['success' => false, 'message' => trans('A user with this e-mail address already exist')]; } else { if (empty($fullname)) { $return = ['success' => false, 'message' => trans('Please provide a full name')]; } else { if ($provider && !$provider->getData()) { $return = ['success' => false, 'message' => trans('Something went wrong with fetching your credentials from an external service')]; } else { $user->set('email', $email); $user->set('fullname', $fullname); if ($user->add($username, $password)) { if ($provider) { $sso = new SsoModel(); $sso->populate(['user' => $user->getPK(), 'provider' => $providername, 'username' => $provider->getUsernameSuggestion(), 'avatar' => $provider->getAvatarSuggestion(), 'profile' => $provider->getProfileSuggestion(), 'uid' => $provider->getUidHash(), 'data' => serialize($provider->getData())]); $sso->insert(); $user->copyAvatarFromSso($sso); } $user->login(); $user->storeCookie($this->includeDomain); Ajde_Session_Flash::alert(sprintf(trans('Welcome %s, you are now logged in'), $fullname)); $return = ['success' => true, 'returnto' => $returnto]; } else { $return = ['success' => false, 'message' => trans('Something went wrong')]; } } } } } } } } } } return $return; }