Пример #1
0
 /**
  *   isValid Checks if username exists in db using User Model's function
  *
  *   @param  $value string username
  *   @return boolean
  */
 public function isValid($value)
 {
     $value = (string) $value;
     $this->_setValue($value);
     $userModel = new Default_Model_User();
     if ($userModel->usernameExists($value)) {
         $this->_error(self::NOT_MATCH);
         return false;
         // if username is registered, form is not valid
     } else {
         return true;
         // if username is registered, form is not valid
     }
 }
Пример #2
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);
     }
 }
Пример #3
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);
     }
 }