public function confirmAction() { $auth = Zend_Auth::getInstance(); $request = $this->getRequest(); $registry = Zend_Registry::getInstance(); $router = Zend_Controller_Front::getInstance()->getRouter(); $config = $registry->get("config"); if ($auth->hasIdentity()) { $registry->set("pleaseSignout", true); return $this->_forward("index", "logout"); } $signUp = Ml_Model_SignUp::getInstance(); $credential = Ml_Model_Credential::getInstance(); $people = Ml_Model_People::getInstance(); $profile = Ml_Model_Profile::getInstance(); if ($config['ssl'] && (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")) { $this->_redirect("https://" . $config['webhostssl'] . $router->assemble(array($request->getUserParams()), "join_emailconfirm"), array("exit")); } $securityCode = $request->getParam("security_code"); $confirmationInfo = $signUp->getByHash($securityCode); if (!$confirmationInfo) { $this->getResponse()->setHttpResponseCode(404); return $this->_forward("unavailable"); } $form = $signUp->newIdentityForm($securityCode); if ($request->isPost() && $form->isValid($request->getPost())) { $newUsername = $form->getValue("newusername"); $password = $form->getValue("password"); $preUserInfo = array("alias" => $newUsername, "membershipdate" => $confirmationInfo['timestamp'], "name" => $confirmationInfo['name'], "email" => $confirmationInfo['email']); $uid = $people->create($newUsername, $password, $preUserInfo, $confirmationInfo); $getUserByUsername = $people->getByUsername($preUserInfo['alias']); $adapter = $credential->getAuthAdapter($getUserByUsername['id'], $password); if ($adapter) { $result = $auth->authenticate($adapter); if ($result->getCode() != Zend_Auth_Result::SUCCESS) { throw new Exception("Could not authenticate 'just created' user"); } } Zend_Session::regenerateId(); $this->_redirect($router->assemble(array(), "join_welcome"), array("exit")); } $this->view->entry = $confirmationInfo; $this->view->confirmForm = $form; }
public function create($username, $password, $data, $confirmationInfo) { $signUp = Ml_Model_SignUp::getInstance(); $credential = Ml_Model_Credential::getInstance(); $profile = Ml_Model_Profile::getInstance(); $this->_dbAdapter->beginTransaction(); try { $signUp->delete($confirmationInfo['id']); $this->_dbTable->insert($data); $uid = $this->_dbAdapter->lastInsertId(); if (!$uid) { throw new Exception("Failed to create user account"); } $credential->setCredential($uid, $password); $profile->create($uid); $this->_dbAdapter->commit(); } catch (Exception $e) { $this->_dbAdapter->rollBack(); throw $e; } return $uid; }
public function indexAction() { $request = $this->getRequest(); $registry = Zend_Registry::getInstance(); $router = Zend_Controller_Front::getInstance()->getRouter(); $config = $registry->get("config"); $people = Ml_Model_People::getInstance(); $profile = Ml_Model_Profile::getInstance(); $form = Ml_Model_Account::settingsForm(); $signedUserInfo = $registry->get("signedUserInfo"); $profileInfo = $profile->getById($signedUserInfo['id']); //only data that can be changed can be here $listOfData = array("name" => $signedUserInfo['name'], "email" => $signedUserInfo['email'], "private_email" => $signedUserInfo['private_email'], "about" => $profileInfo['about'], "website" => $profileInfo['website'], "location" => $profileInfo['location']); $form->setDefaults($listOfData); if ($request->isPost()) { $form->isValid($request->getPost()); $errors = $form->getErrors(); $changeData = array(); $rec = $form->getValues(); //update foreach ($listOfData as $key => $value) { if (empty($errors[$key]) && $rec[$key] != $value) { $changeData[$key] = $rec[$key]; } } if (!empty($changeData)) { $changeDataLessEmail = $changeData; if (isset($changeData['email'])) { unset($changeDataLessEmail['email']); } if (!empty($changeDataLessEmail)) { //just a small state protection if (isset($changeDataLessEmail['private_email'])) { $changeDataLessEmail['private_email'] = 1; } $profileFields = array("website", "location", "about"); $changeProfileData = array(); foreach ($profileFields as $field) { if (isset($changeDataLessEmail[$field])) { $changeProfileData[$field] = $changeDataLessEmail[$field]; unset($changeDataLessEmail[$field]); } } if (!empty($changeDataLessEmail)) { $people->update($signedUserInfo['id'], $changeDataLessEmail); } if (!empty($changeProfileData)) { if (isset($changeProfileData['about'])) { $purifier = Ml_Model_HtmlPurifier::getInstance(); $changeProfileData['about_filtered'] = $purifier->purify($changeProfileData['about']); } $profile->update($signedUserInfo['id'], $changeProfileData); } $signedUserInfo = array_merge($signedUserInfo, $changeDataLessEmail); $registry->set("signedUserInfo", $signedUserInfo); } if (isset($changeData['about']) && sizeof($changeData) == 1) { $redirectToProfile = true; } } if (isset($changeData['email'])) { $emailChange = Ml_Model_EmailChange::getInstance(); $securitycode = $emailChange->newChange($signedUserInfo['id'], $changeData['email'], $signedUserInfo['name']); $mail = new Zend_Mail(); $this->view->securitycode = $securitycode; $mail->setBodyText($this->view->render("account/emailChange.phtml"))->setFrom($config['robotEmail']['addr'], $config['robotEmail']['name'])->addTo($changeData['email'], $signedUserInfo['name'])->setSubject('Changing your ' . $config['applicationname'] . ' email')->send(); $this->view->changeEmail = true; } else { if (isset($redirectToProfile)) { $this->_redirect($router->assemble(array("username" => $signedUserInfo['alias']), "profile") . "?about_check=true", array("exit")); } } } $this->view->accountForm = $form; }
public function infoAction() { //@todo route: do it the right way! $router = new Zend_Controller_Router_Rewrite(); $routeConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/defaultRoutes.ini'); $router->addConfig($routeConfig, 'routes'); $registry = Zend_Registry::getInstance(); $config = $registry->get("config"); $request = $this->getRequest(); $params = $request->getParams(); $people = Ml_Model_People::getInstance(); $profile = Ml_Model_Profile::getInstance(); $share = Ml_Model_Share::getInstance(); if (isset($params['username'])) { $userInfo = $people->getByUsername($params['username']); } else { if (isset($params['user_id'])) { $userInfo = $people->getById($params['user_id']); } else { if (isset($params['email'])) { $userInfo = $people->getByEmail($params['email']); if (!empty($userInfo) && $userInfo['private_email'] == true) { $registry->set("notfound", true); throw new Exception("User not found."); } } else { throw new Exception("No user params were given."); } } } if (empty($userInfo)) { $registry->set("notfound", true); throw new Exception("User not found."); } $profileInfo = $profile->getById($userInfo['id']); $doc = new Ml_Model_Dom(); $doc->formatOutput = true; $rootElement = $doc->createElement("person"); $doc->appendChild($rootElement); $rootElement->appendChild($doc->newTextAttribute('id', $userInfo['id'])); $avatarInfo = unserialize($userInfo['avatarInfo']); if (isset($avatarInfo['secret'])) { $iconSecret = $avatarInfo['secret']; } else { $iconSecret = ''; } $rootElement->appendChild($doc->newTextAttribute('iconsecret', $iconSecret)); $userData = array("username" => $userInfo['alias'], "realname" => $userInfo['name']); if (!$userInfo['private_email']) { $userData["mbox_sha1sum"] = sha1("mailto:" . $userInfo['email']); } $userData["location"] = $profileInfo['location']; $userData["url"] = "http://" . $config['webhost'] . $router->assemble(array("username" => $userInfo['alias']), "filestream_1stpage"); foreach ($userData as $field => $data) { $rootElement->appendChild($doc->newTextElement($field, $data)); } $sharesCounter = $share->countOfUser($userInfo['id']); $sharesElement = $doc->createElement("files"); $sharesCounterElement = $doc->createElement("count"); $sharesCounterElement->appendChild($doc->createTextNode($sharesCounter)); $sharesElement->appendChild($sharesCounterElement); $rootElement->appendChild($sharesElement); $this->_helper->printResponse($doc); }