示例#1
0
 /**
  * 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;
 }
 /**
  * heartbeat actions (via continuous ajax call)
  */
 public function heartbeatAction()
 {
     $Notifications = new Application_Model_Notifications();
     $notifications = $Notifications->getNotifications(true, 10);
     $notifications_count = $Notifications->getUnreadNotificationsCount();
     $this->view->notifications = $notifications;
     $notifications_html = $this->view->render('/partial/notifications_popover.phtml');
     // new messages count
     $Messages = new Application_Model_Messages();
     $new_messages_count = $Messages->getMessagesCount(false, true);
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     // we will use timestamp format here since it's easier to calculate diff with ANSI SQL
     $ProfilesMeta->metaUpdate('last_heartbeat', time());
     $out = array('notification_count' => $notifications_count, 'notification_html' => $notifications_html, 'new_messages' => $new_messages_count);
     // trigger hooks
     Zend_Registry::get('hooks')->trigger('hook_app_heartbeat', $out);
     $this->_helper->json($out);
 }
示例#3
0
/**
 * 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;
}
示例#4
0
 /**
  * Lost password
  */
 public function submitLostPasswordForm($form)
 {
     $front = Zend_Controller_Front::getInstance();
     if ($form->isValid($_POST)) {
         $name = $form->getValue('name');
         $Profiles = new Application_Model_Profiles();
         $nameRow = $Profiles->getProfileByField('name', $name);
         // maybe user is entering email?
         $nameRow_byEmail = $Profiles->getProfileByField('email', $name);
         if ($nameRow_byEmail) {
             $nameRow = $Profiles->getProfileByField('name', $nameRow_byEmail->name);
         }
         if ($nameRow && $Profiles->isActivated($nameRow->name) && $nameRow->is_hidden == 0) {
             $resetPasswordKey = $Profiles->generateActivationKey($nameRow->email);
             $ProfilesMeta = new Application_Model_ProfilesMeta();
             $profile = $ProfilesMeta->metaUpdate('password_reset', $resetPasswordKey, $nameRow->id);
             // password recovery email
             $ret = Application_Plugin_Common::sendRecoveryEmail($nameRow->email, $name, $resetPasswordKey);
             // show info message
             if ($ret) {
                 Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('We have sent an email to your registered email address. Follow the instructions and you will be able to enter a new password.'), 'off');
             }
             // flush url
             Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl('');
         } else {
             sleep(2);
             $form->getElement('name')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('Username does not exists')));
         }
     }
     return $form;
 }
 /**
  * Edit page
  */
 public function pageAction()
 {
     $Profiles = new Application_Model_Profiles();
     $request = $this->getRequest();
     $profile_id = $request->getParam('id', null);
     $profile = $Profiles->getProfileByField('id', $profile_id);
     $this->view->sidebar_editprofile = $profile;
     // attach sidebar box
     Zend_Registry::get('hooks')->attach('hook_view_sidebar', 5, function () {
         echo Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->view->render('/_sidebar/editprofile.phtml');
     });
     $edit_form = new Application_Form_AdminPage();
     $this->view->edit_form = $edit_form;
     if ($request->isPost() && $profile_id && $edit_form->isValid($_POST)) {
         $owner_profile = $Profiles->getProfileByField('name', $edit_form->getValue('owner'));
         $profile->owner = $owner_profile->id;
         $profile->name = $edit_form->getValue('name');
         $profile->screen_name = $edit_form->getValue('screen_name');
         $profile->is_hidden = $edit_form->getValue('is_hidden');
         $profile->save();
         $ProfilesMeta = new Application_Model_ProfilesMeta();
         $ProfilesMeta->metaUpdate('description', $edit_form->getValue('description'), $profile_id);
         $ProfilesMeta->metaUpdate('badges', $edit_form->getValue('badges'), $profile_id);
         Application_Plugin_Alerts::success($this->view->translate('Page updated'));
         // flush url
         $this->redirect('admin/page/id/' . $profile_id);
     }
 }
 /**
  * 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('');
             }
         }
     }
 }
示例#7
0
 /**
  * Create new page - add defaults & save
  */
 public function createNewPage(Application_Model_Profiles_Row $profile)
 {
     $profile->type = 'page';
     $profile->avatar = 'default/pages.jpg';
     $profile->cover = 'default/' . rand(1, 3) . '.jpg';
     $profile->is_hidden = 0;
     try {
         $created_id = $profile->save();
     } catch (Zend_Db_Exception $e) {
         Application_Plugin_Common::log($e->getMessage());
     }
     $ProfilesMeta = new Application_Model_ProfilesMeta();
     $ProfilesMeta->metaUpdate('date_created', Application_Plugin_Common::now(), $created_id);
     $user_id = Zend_Auth::getInstance()->getIdentity()->id;
     return $profile;
 }
 /**
  * Create a page
  */
 public function createpageAction()
 {
     $this->buildMenu(true);
     $request = $this->getRequest();
     $Profiles = new Application_Model_Profiles();
     $profile_form = new Application_Form_AddPage();
     $this->view->profile_form = $profile_form;
     if ($request->isPost() && $profile_form->isValid($_POST)) {
         if ($Profiles->getProfile($profile_form->getValue('name'), true)) {
             $profile_form->getElement('name')->setErrors(array(Zend_Registry::get('Zend_Translate')->translate('This username is not available')));
             return;
         }
         $profile = $Profiles->createRow();
         $profile->owner = Zend_Auth::getInstance()->getIdentity()->id;
         $profile->name = $profile_form->getValue('name');
         $profile->screen_name = $profile_form->getValue('screen_name');
         $profile->profile_privacy = 'public';
         $Profiles->createNewPage($profile);
         $ProfilesMeta = new Application_Model_ProfilesMeta();
         $ProfilesMeta->metaUpdate('description', $profile_form->getValue('description'), $profile->id);
         Application_Plugin_Alerts::success($this->view->translate('New page created'));
         $this->redirect('editprofile/listpages');
     }
 }