/** * Login user */ public static function loginUser($user_data, $authAdapter, $authStorage) { $Profiles = new Application_Model_Profiles(); $ProfilesMeta = new Application_Model_ProfilesMeta(); // everything ok, login user $user_data = $authAdapter->getResultRowObject(); // update fields $Profiles->updateField($user_data->name, 'relogin_request', 0); $authStorage->write($user_data); // update last login date $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $user_data->id); // set user specific language after login $session = new Zend_Session_Namespace('Default'); $session->language = $user_data->language; return; }
/** * Register with facebook */ function registerWithFacebook() { // flush if already logged in Zend_Auth::getInstance()->clearIdentity(); $session = new Zend_Session_Namespace('Default'); $email = $session->fb_user_email; $avatar = $session->fb_avatar; // do not allow direct access - without fb_user_email inside session if (!$session->fb_user_email) { Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl(''); } require_once 'Form.php'; $registerwithfacebook_form = new Addon_FacebookRegisterForm(); $Profiles = new Application_Model_Profiles(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($registerwithfacebook_form->isValid($_POST)) { $name = $registerwithfacebook_form->getValue('name'); $user = $Profiles->createRow(); $user->name = $name; $user->email = $email; $user->password = ''; $user->activationkey = 'activated'; $user->language = Zend_Registry::get('config')->get('default_language'); $user = $Profiles->createNewUser($user, 'facebook'); // update last login date $ProfilesMeta = new Application_Model_ProfilesMeta(); $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $user->id); $Storage = new Application_Model_Storage(); $StorageAdapter = $Storage->getAdapter(); $defaultres = 64; $bigres = Zend_Registry::get('config')->get('avatar_size') ? Zend_Registry::get('config')->get('avatar_size') : $defaultres; // get the image $c = new Zend_Http_Client(); $c->setUri($avatar); $result = $c->request('GET'); $img = imagecreatefromstring($result->getBody()); // create regular avatar image, resample and store $imgname = 'profileimage_' . $name . '.jpg'; imagejpeg($img, TMP_PATH . '/' . $imgname); Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $imgname, TMP_PATH . '/' . $imgname, $defaultres, $defaultres, false); $new_filename = $StorageAdapter->moveFileToStorage($imgname, 'avatar'); $Profiles->updateField($name, 'avatar', $new_filename); // create big avatar image, resample and store $imgname = 'bigprofileimage_' . $name . '.jpg'; imagejpeg($img, TMP_PATH . '/' . $imgname); Application_Plugin_ImageLib::resample(TMP_PATH . '/' . $imgname, TMP_PATH . '/' . $imgname, $bigres, $bigres, false); $big_avatar = $StorageAdapter->moveFileToStorage($imgname, 'avatar'); $ProfilesMeta->metaUpdate('big_avatar', $big_avatar, $user->id); // free img resource imagedestroy($img); // login user $emailAuthAdapter = Application_Plugin_Common::getEmailAuthAdapter($email); $auth = Zend_Auth::getInstance(); $auth->authenticate($emailAuthAdapter); $identity = $emailAuthAdapter->getResultRowObject(); $authStorage = $auth->getStorage(); $authStorage->write($identity); // clear session data $session->fb_user_email = ''; $session->fb_user_display_name = ''; $session->fb_avatar = ''; $user_id = $user->id; // trigger hooks Zend_Registry::get('hooks')->trigger('hook_firsttimelogin', $user_id); // show welcome message Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('Welcome to the network.'), 'on'); Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl(''); } } echo $registerwithfacebook_form; }
/** * logged in user actions on each page load, username row db load */ protected function _initUserPreloads() { // return on guests if (!Zend_Auth::getInstance()->hasIdentity()) { return; } // check if cookie is ok if (!isset(Zend_Auth::getInstance()->getIdentity()->name) || !isset(Zend_Auth::getInstance()->getIdentity()->id)) { Zend_Auth::getInstance()->clearIdentity(); return; } // load user from db $Profiles = new Application_Model_Profiles(); $current_user = $Profiles->getProfile(Zend_Auth::getInstance()->getIdentity()->name, true); // load users meta from db $ProfilesMeta = new Application_Model_ProfilesMeta(); $current_user_meta = $ProfilesMeta->getMetaValues(Zend_Auth::getInstance()->getIdentity()->id); if (!$current_user) { Zend_Auth::getInstance()->clearIdentity(); return; } // re-login requests, when user has to re-login for some reason if ($current_user->relogin_request == 1) { $Profiles->updateField($current_user->name, 'relogin_request', 0); Zend_Auth::getInstance()->clearIdentity(); } // set default post privacy Zend_Registry::set('default_privacy', $current_user->default_privacy); // save all profile's meta data Zend_Registry::set('current_user_meta', $current_user_meta); return; }
/** * Change language */ public function languageAction() { Application_Plugin_Common::redirectOnDemoAccount(); $request = $this->getRequest(); $session = new Zend_Session_Namespace('Default'); $new_lang = $request->getParam('code'); $translate = Zend_Registry::get('Zend_Translate'); // change current language if ($new_lang && in_array($new_lang, $translate->getList())) { $session->language = $new_lang; if (Zend_Auth::getInstance()->hasIdentity()) { // update user's default language $Profiles = new Application_Model_Profiles(); $Profiles->updateField(Zend_Auth::getInstance()->getIdentity()->name, 'language', $new_lang); } } $this->redirect(''); }
/** * Change default privacy (via ajax) */ public function defaultprivacyAction() { $default_privacy = $this->getRequest()->getParam('privacy'); $privacy_levels = Zend_Registry::get('post_privacy_array'); $ret = false; if (array_key_exists($default_privacy, $privacy_levels)) { $Profiles = new Application_Model_Profiles(); $ret = $Profiles->updateField(Zend_Auth::getInstance()->getIdentity()->name, 'default_privacy', $default_privacy); Zend_Registry::set('default_privacy', $default_privacy); } $this->getHelper('json')->sendJson($ret); }