Пример #1
0
 public function sendAction()
 {
     // Get authentication
     $auth = Zend_Auth::getInstance();
     $absoluteBaseUrl = strtolower(trim(array_shift(explode('/', $_SERVER['SERVER_PROTOCOL'])))) . '://' . $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getBaseUrl();
     // If user has identity
     if ($auth->hasIdentity()) {
         // Get requests
         $params = $this->getRequest()->getParams();
         // Get content type
         $receiver = isset($params['username']) ? $params['username'] : '';
         $model_user = new Default_Model_User();
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         if (!$model_user->usernameExists($receiver)) {
             // If not logged, redirecting to system message page
             $message = 'privmsg-send-invalid-receiver';
             $this->flash($message, $url);
         } else {
             if ($model_user->getIdByUsername($receiver) == $auth->getIdentity()->user_id) {
                 $message = 'privmsg-send-own-account';
                 $this->flash($message, $url);
             }
         }
         // Receiver's username to view
         $this->view->receiver = $receiver;
         // Sender's username to view
         $this->view->sender = $auth->getIdentity()->username;
         // Creating data array for form's hidden fields
         $data = array();
         $data['sender_id'] = $auth->getIdentity()->user_id;
         $data['receiver_id'] = $model_user->getIdByUsername($receiver);
         $form = new Default_Form_PrivMsgForm(null, $data);
         $this->view->form = $form;
         // If private message is posted
         if ($this->getRequest()->isPost()) {
             // Get private message data
             $data = $this->getRequest()->getPost();
             if ($form->isValid($data)) {
                 // Add a private message
                 $Default_Model_privmsg = new Default_Model_PrivateMessages();
                 if ($Default_Model_privmsg->addMessage($data) && $data['privmsg_sender_id'] != $data['privmsg_receiver_id']) {
                     $message = 'privmsg-add-successful';
                 } else {
                     $message = 'privmsg-add-not-successful';
                 }
                 // Send email to user about new private message
                 // if user allows private message notifications
                 $receiverId = $data['privmsg_receiver_id'];
                 $notificationsModel = new Default_Model_Notifications();
                 $notifications = $notificationsModel->getNotificationsById($receiverId);
                 if (in_array('privmsg', $notifications)) {
                     $senderName = $auth->getIdentity()->username;
                     $receiverUsername = $model_user->getUserNameById($receiverId);
                     $emailNotification = new Oibs_Controller_Plugin_Email();
                     $emailNotification->setNotificationType('privmsg')->setSenderId($auth->getIdentity()->user_id)->setReceiverId($receiverId)->setParameter('URL', $absoluteBaseUrl . "/en")->setParameter('SENDER-NAME', $senderName)->setParameter('MESSAGE-TITLE', $data['privmsg_header'])->setParameter('MESSAGE-BODY', nl2br($data['privmsg_message']));
                     if ($emailNotification->isValid()) {
                         $emailNotification->send();
                     } else {
                         //echo $emailNotification->getErrorMessage(); die;
                     }
                 }
                 $this->flash($message, $url);
             }
         }
         // end if
     } else {
         // If not logged, redirecting to system message page
         $message = 'privmsg-send-not-logged';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Пример #2
0
 public function removeroleAction()
 {
     $params = $this->getRequest()->getParams();
     $username = $params['user'];
     $role = $params['role'];
     if ($username != "" && $role != "") {
         $user = new Default_Model_User();
         if ($user->usernameExists($username)) {
             $id_usr = $user->getIdByUsername($username);
             $userProfiles = new Default_Model_UserProfiles();
             $user_roles = $userProfiles->getUserRoles($id_usr);
             if (in_array($role, $user_roles)) {
                 foreach ($user_roles as $key => $value) {
                     if ($value == $role) {
                         unset($user_roles[$key]);
                     }
                 }
                 $user_roles = array_values($user_roles);
                 if ($userProfiles->setUserRoles($id_usr, $user_roles)) {
                     $message = 'admin-removerole-successful';
                     $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                     $this->flash($message, $url);
                 } else {
                     $message = 'admin-removerole-not-successful';
                     $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                     $this->flash($message, $url);
                 }
             } else {
                 $message = 'admin-removerole-role-not-found';
                 $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                 $this->flash($message, $url);
             }
         } else {
             $message = 'admin-editrole-invalid-user';
             $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
             $this->flash($message, $url);
         }
     } else {
         $message = 'admin-editrole-missing-username-role';
         $url = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->flash($message, $url);
     }
 }
Пример #3
0
 private function isAccountAdmin($userId)
 {
     $userModel = new Default_Model_User();
     if ($userId == $userModel->getIdByUsername($this->id)) {
         $this->admin = true;
         return true;
     }
     return false;
 }
Пример #4
0
 /**
  * registerAction
  *
  * User registration page and post-validation actions
  *
  * @author Joel Peltonen
  * @author ...?
  */
 public function registerAction()
 {
     // if user is logged in, redirect away
     $auth = Zend_Auth::getInstance();
     if ($auth->hasIdentity()) {
         $urlHelper = $this->_helper->getHelper('url');
         $target = $urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
         $this->_redirect($target);
     }
     // Create new registration form
     $form = new Default_Form_RegistrationForm();
     $this->view->form = $form;
     // Get requests
     //$request = $this->getRequest();
     // get and validate form data
     if ($this->_request->isPost()) {
         $formData = $this->_request->getPost();
         // If form is valid, handle database insertions
         // Else form population (automatic)
         if ($form->isValid($formData)) {
             // user data handling
             $user = new Default_Model_User();
             if (!$user->registerUser($formData)) {
                 $redirect = $this->_urlHelper->url(array('controller' => 'msg', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true);
                 $this->flash('registration-usermodel-data-procesing-failure', $redirect);
             }
             // Add register to log
             $logger = Zend_Registry::get('logs');
             if (isset($logger['register'])) {
                 $message = sprintf('Successful register attempt from %s user %s', $_SERVER['REMOTE_ADDR'], $formData['username']);
                 $logger['register']->notice($message);
             }
             // Fetch user id
             $uid = $user->getIdByUsername($formData['username']);
             $userProfiles = new Default_Model_UserProfiles();
             $userProfiles->setUserEmployment($uid, $formData, 0);
             $userProfiles->setUserCity($uid, $formData, 1);
             // check if user is logged in
             $auth = Zend_Auth::getInstance();
             $username = $formData['username'];
             $password = $formData['password'];
             // $model = new Default_Model_User();
             $id = $user->getIdByUsername($username);
             $user = new Default_Model_User($id);
             $result = $user->loginUser($formData);
             // the logging in worked;
             if ($result == true) {
                 // Get user id
                 //$id = $adapter->getResultRowObject()->id_usr;
                 // record login attempt
                 $user->loginSuccess();
                 // create identity data and write it to session
                 $identity = $user->createAuthIdentity();
                 $auth->getStorage()->write($identity);
                 // Add login to log
                 $logger = Zend_Registry::get('logs');
                 if (isset($logger['login'])) {
                     $message = sprintf('Successful login attempt from %s user %s', $_SERVER['REMOTE_ADDR'], $identity->username);
                     $logger['login']->notice($message);
                 }
                 // send phase 2 page
                 $urlHelper = $this->_helper->getHelper('url');
                 $redirect = $urlHelper->url(array('controller' => 'account', 'action' => 'registercomplete', 'language' => $this->view->language), 'lang_default', true);
                 $this->_redirect($redirect);
             } else {
                 // logging in failed
                 $this->view->errormsg = $this->view->translate('account-login-not-successful');
             }
         } else {
             $formData['captcha_text'] = '';
             $form->populate($formData);
         }
     }
 }