/** * Follow user toggle */ public function toggleFollowed($name) { if (!Zend_Auth::getInstance()->hasIdentity()) { return null; } $Profiles = new Application_Model_Profiles(); $Notifications = new Application_Model_Notifications(); $translator = Zend_Registry::get('Zend_Translate'); $user_id = Zend_Auth::getInstance()->getIdentity()->id; $follow_profile = $Profiles->getProfile($name); // no or bad profile if (!$follow_profile || !isset($follow_profile->id)) { return; } if ($follow_profile->type === 'page') { return; } $is_group = $follow_profile->type === 'group' ? true : false; $follow_id = $follow_profile->id; if ($this->isFollowing($user_id, $follow_id)) { if ($is_group) { // delete mutual connection $ret = $this->removeConnections($follow_id, $user_id); if ($ret == 2) { Application_Plugin_Alerts::info(sprintf($translator->translate('You have left the group %s'), $follow_profile->screen_name)); } else { Application_Plugin_Alerts::info($translator->translate('You request has been canceled')); } } else { $Notifications->pushNotification(array($follow_id), 6, 'profile', $user_id); $this->delete(array('follow_id = ?' => (int) $follow_id, 'user_id = ?' => (int) $user_id)); Application_Plugin_Alerts::info(sprintf($translator->translate('You have stopped following %s'), $follow_profile->screen_name)); } return; } else { if ($is_group) { $data = array('user_id' => $user_id, 'follow_id' => $follow_id, 'created_on' => Application_Plugin_Common::now()); $ret = $this->insert($data); if ($follow_profile->profile_privacy === 'friends' && $follow_profile->owner != $user_id) { // admin will have to confirm this Application_Plugin_Alerts::success(sprintf($translator->translate('Your request to join this group has been sent to %s'), $follow_profile->screen_name)); // notify group admin that new user has requested membership $Notifications->pushNotification(array($follow_profile->owner), 12, 'profile', $follow_id); } else { // join the group by adding mutual follow $data = array('user_id' => $follow_id, 'follow_id' => $user_id, 'created_on' => Application_Plugin_Common::now()); $this->insert($data); Application_Plugin_Alerts::success(sprintf($translator->translate('You have joined the group %s'), $follow_profile->screen_name)); } } else { $data = array('user_id' => $user_id, 'follow_id' => $follow_id, 'created_on' => Application_Plugin_Common::now()); $this->insert($data); if ($this->areFriends($user_id, $follow_id)) { // follow, areFriends // are friends now, notify user $Notifications->pushNotification(array($follow_id), 4, 'profile', $user_id); if ($is_group) { Application_Plugin_Alerts::success(sprintf($translator->translate('You have joined the group %s'), $follow_profile->screen_name)); } else { Application_Plugin_Alerts::success(sprintf($translator->translate('You are now friends with %s'), $follow_profile->screen_name)); } return; } // new follower, notify user $Notifications->pushNotification(array($follow_id), 3, 'profile', $user_id); Application_Plugin_Alerts::success(sprintf($translator->translate('You are now following %s'), $follow_profile->screen_name)); } // follow return; } return false; }
/** * Fetch and prepare profiles for view */ public function prepareProfiles($type, $filters = false) { $Profiles = new Application_Model_Profiles(); $count = $Profiles->searchProfiles($this->search_term, $filters, $type, true); $this->view->pagination_last_page = (int) ceil($count / (int) Zend_Registry::get('config')->get('pagination_limit')); $this->view->pagination_current_page = $this->page; $Profiles->page_number = $this->page; if ($count > 0) { $this->view->profiles = $Profiles->searchProfiles($this->search_term, $filters, $type); } else { Application_Plugin_Alerts::info($this->view->translate('Nothing found...'), 'off'); } // set single view script $this->render('profiles'); }
/** * Register submit */ public function submitRegisterForm($form) { if ($form->isValid($_POST)) { $Profiles = new Application_Model_Profiles(); $name = $form->getValue('regname'); $email = $form->getValue('regemail'); $hash = new Application_Plugin_Phpass(); $password = $hash->HashPassword($form->getValue('regpassword')); $user = $Profiles->createRow(); $user->name = $name; $user->email = $email; $user->password = $password; if (Zend_Registry::get('config')->get('user_activation_disabled')) { // create new user withot activation & login $user->activationkey = 'activated'; $new_profile = $Profiles->createNewUser($user); // auto-login user and store identity $authAdapter = Application_Plugin_Common::getAuthAdapter(); $authAdapter->setIdentity($new_profile->email)->setCredential('whatever')->setCredentialTreatment('autologin'); $auth = Zend_Auth::getInstance(); $auth->authenticate($authAdapter); $identity = $authAdapter->getResultRowObject(); $authStorage = $auth->getStorage(); $authStorage->write($identity); // update last login date $ProfilesMeta = new Application_Model_ProfilesMeta(); $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $identity->id); // show welcome message Application_Plugin_Alerts::success($this->view->translate('Welcome to the network.'), 'on'); } else { // create activation key and sent it to user email $key = $Profiles->generateActivationKey($email); $user->activationkey = $key; $ret = Application_Plugin_Common::sendActivationEmail($email, $name, $key); // email has been sent, proceed if ($ret) { // show success message Application_Plugin_Alerts::info(Zend_Registry::get('Zend_Translate')->translate('Please Check your Inbox and come back after you activate your account.'), 'off'); // build url $base_url = Application_Plugin_Common::getFullBaseUrl(); $resendactivation_link = $base_url . '/index/activate/resend/' . $user->name; Application_Plugin_Alerts::info('<a href="' . $resendactivation_link . '">' . Zend_Registry::get('Zend_Translate')->translate('Click here to resend the activation email') . '</a>', 'off', false); // create new user $new_profile = $Profiles->createNewUser($user); } else { // show error message Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Something went wrong, email was not sent.'), 'off'); Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl(''); return; } } // flush url Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl(''); } return $form; }
/** * Activation link lands here to activate user account */ public function activateAction() { $this->_helper->_layout->setLayout('layout_wide'); // flush if already logged in Zend_Auth::getInstance()->clearIdentity(); $activateaccount_form = new Application_Form_ActivateAccount(); $this->view->activateaccount_form = $activateaccount_form; $key = $this->getRequest()->getParam('key', false); $resend_username = $this->getRequest()->getParam('resend', false); $Profiles = new Application_Model_Profiles(); $ProfilesMeta = new Application_Model_ProfilesMeta(); $userData = $Profiles->getProfileByField('activationkey', $key); if (!$userData || $key == 'activated') { // try if this is a resend $userData = $Profiles->getProfile($resend_username); if (!$userData || $userData->activationkey == 'activated') { $this->redirect(''); } else { $resend_lock = $ProfilesMeta->getMetaValue('resend_activation_lock', $userData->id); $hour_lock = date('H'); // prevent too many attempts if ($resend_lock && $resend_lock == $hour_lock) { Application_Plugin_Alerts::info(Zend_Registry::get('Zend_Translate')->translate('Please Check your Inbox and come back after you activate your account.'), 'off'); $this->redirect(''); } $ret = Application_Plugin_Common::sendActivationEmail($userData->email, $userData->name, $userData->activationkey); // email has been sent, show success message if ($ret) { Application_Plugin_Alerts::info(Zend_Registry::get('Zend_Translate')->translate('Please Check your Inbox and come back after you activate your account.'), 'off'); // once per day $ProfilesMeta->metaUpdate('resend_activation_lock', $hour_lock, $userData->id); } else { // show error message Application_Plugin_Alerts::error(Zend_Registry::get('Zend_Translate')->translate('Something went wrong, email was not sent.'), 'off'); } $this->redirect(''); } } $request = $this->getRequest(); if ($request->isPost() && isset($_POST['identifier']) && $_POST['identifier'] == 'ActivateAccount') { if ($activateaccount_form->isValid($_POST)) { if ($Profiles->activateAccount($key)) { // auto-login user and store identity $authAdapter = Application_Plugin_Common::getAuthAdapter(); $authAdapter->setIdentity($userData->email)->setCredential('whatever')->setCredentialTreatment('autologin'); $auth = Zend_Auth::getInstance(); $auth->authenticate($authAdapter); $identity = $authAdapter->getResultRowObject(); $authStorage = $auth->getStorage(); $authStorage->write($identity); // update last login date $ProfilesMeta = new Application_Model_ProfilesMeta(); $ProfilesMeta->metaUpdate('last_login', Application_Plugin_Common::now(), $identity->id); // show welcome message Application_Plugin_Alerts::success($this->view->translate('Welcome to the network.'), 'on'); $this->redirect(''); } } } }