Beispiel #1
0
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (UserIdentityService::isGuest() && (int) $this->getSetting('user_allow_register')) {
         // get an user form
         $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones())->showCaptcha(true);
         // validate the form
         if ($this->getRequest()->isPost() && $this->getRequest()->getPost('form_name') == $userForm->getFormName()) {
             // make certain to merge the files info!
             $post = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
             // fill the form with received values
             $userForm->getForm()->setData($post, false);
             // save data
             if ($userForm->getForm()->isValid()) {
                 // add a new user with a particular status
                 $status = (int) $this->getSetting('user_auto_confirm') ? true : false;
                 $userInfo = $this->getModel()->addUser($userForm->getForm()->getData(), LocalizationService::getCurrentLocalization()['language'], $status, $this->getRequest()->getFiles()->avatar, true);
                 // the user has been added
                 if (is_array($userInfo)) {
                     // check the user status
                     if (!$status) {
                         // get user activate url
                         if (false !== ($activateUrl = $this->getView()->pageUrl('user-activate', ['user_id' => $userInfo['user_id']]))) {
                             // send an email activate notification
                             EmailNotificationUtility::sendNotification($userInfo['email'], $this->getSetting('user_email_confirmation_title'), $this->getSetting('user_email_confirmation_message'), ['find' => ['RealName', 'SiteName', 'ConfirmationLink', 'ConfCode'], 'replace' => [$userInfo['nick_name'], $this->getSetting('application_site_name'), $this->getView()->url('page', ['page_name' => $activateUrl, 'slug' => $userInfo['slug']], ['force_canonical' => true]), $userInfo['activation_code']]], true);
                             $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('We sent a message with a confirmation code to your registration e-mail'));
                         } else {
                             $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your profile will be activated after checking'));
                         }
                         $this->reloadPage();
                     } else {
                         // login and redirect the registered user
                         return $this->loginUser($userInfo['user_id'], $userInfo['nick_name'], false);
                     }
                 } else {
                     $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Error occurred'));
                 }
                 return $this->reloadPage();
             }
         }
         return $this->getView()->partial('user/widget/register', ['user_form' => $userForm->getForm()]);
     }
     return false;
 }
Beispiel #2
0
 /**
  * Set user time zone
  *
  * @param string $timeZone
  * @param string $requestSignature
  * @throws \XmlRpc\Exception\XmlRpcActionDenied
  * @return array
  */
 public function setUserTimeZone($timeZone, $requestSignature)
 {
     // check request signature
     if (!$this->isRequestAuthorized([$timeZone], $requestSignature)) {
         throw new XmlRpcActionDenied(self::REQUEST_UNAUTHORIZED);
     }
     // check an user's permission
     if (!AclService::checkPermission('xmlrpc_set_user_timezone')) {
         throw new XmlRpcActionDenied(self::REQUEST_DENIED);
     }
     // check received time zone
     if (false === ($timeZoneId = array_search($timeZone, TimeZoneService::getTimeZones()))) {
         throw new XmlRpcActionDenied(self::REQUEST_DENIED_WRONG_TIME_ZONE);
     }
     // update the user's time zone
     if (true === ($result = $this->getModel()->setUserTimeZone($this->userIdentity['user_id'], $this->userIdentity['nick_name'], $timeZoneId))) {
         return self::SUCCESSFULLY_RESPONSE;
     }
     return self::REQUEST_BROKEN;
 }
Beispiel #3
0
 /**
  * Get widget content
  *
  * @return string|boolean
  */
 public function getContent()
 {
     if (!UserIdentityService::isGuest()) {
         // get an user form
         $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones())->setUserId(UserIdentityService::getCurrentUserIdentity()['user_id'])->setUserAvatar(UserIdentityService::getCurrentUserIdentity()['avatar']);
         // fill the form with default values
         $userForm->getForm()->setData(UserIdentityService::getCurrentUserIdentity());
         // validate the form
         if ($this->getRequest()->isPost() && $this->getRequest()->getPost('form_name') == $userForm->getFormName()) {
             // make certain to merge the files info!
             $post = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
             // fill the form with received values
             $userForm->getForm()->setData($post, false);
             // save data
             if ($userForm->getForm()->isValid()) {
                 // set status
                 $status = (int) $this->getSetting('user_auto_confirm') || UserIdentityService::getCurrentUserIdentity()['role'] == AclBaseModel::DEFAULT_ROLE_ADMIN ? true : false;
                 $deleteAvatar = (int) $this->getRequest()->getPost('avatar_delete') ? true : false;
                 // edit current user's info
                 $result = $this->getModel()->editUser(UserIdentityService::getCurrentUserIdentity(), $userForm->getForm()->getData(), $status, $this->getRequest()->getFiles()->avatar, $deleteAvatar, true);
                 if (true === $result) {
                     if ($status) {
                         $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your account has been edited'));
                     } else {
                         $this->getFlashMessenger()->setNamespace('success')->addMessage($this->translate('Your account will be active after checking'));
                         // redirect to login page
                         $loginUrl = $this->getView()->pageUrl('login');
                         return $this->redirectTo(['page_name' => false !== $loginUrl ? $loginUrl : '']);
                     }
                 } else {
                     $this->getFlashMessenger()->setNamespace('error')->addMessage($this->translate('Error occurred'));
                 }
                 return $this->reloadPage();
             }
         }
         return $this->getView()->partial('user/widget/edit', ['user_form' => $userForm->getForm()]);
     }
     return false;
 }
Beispiel #4
0
 /**
  * Init time zone
  */
 protected function initTimeZone()
 {
     try {
         // get list of all registered time zones
         $registeredTimeZones = TimeZoneService::getTimeZones();
         // what should we use here, user's or default time zone
         $defaultTimeZone = !empty($this->userIdentity['time_zone_name']) ? $this->userIdentity['time_zone_name'] : SettingService::getSetting('application_default_time_zone');
         // check default time zone existing
         if (!in_array($defaultTimeZone, $registeredTimeZones)) {
             $defaultTimeZone = current($registeredTimeZones);
         }
         // change time zone settings
         if ($defaultTimeZone != date_default_timezone_get()) {
             date_default_timezone_set($defaultTimeZone);
         }
         // get difference to greenwich time (GMT) with colon between hours and minutes
         $date = new DateTime();
         $applicationInit = $this->serviceLocator->get('Application\\Model\\ModelManager')->getInstance('Application\\Model\\ApplicationInit')->setTimeZone($date->format('P'));
     } catch (Exception $e) {
         ApplicationErrorLogger::log($e);
     }
 }
 /**
  * Add a new user
  */
 public function addUserAction()
 {
     // get an user form
     $userForm = $this->getServiceLocator()->get('Application\\Form\\FormManager')->getInstance('User\\Form\\User')->setModel($this->getModel())->setTimeZones(TimeZoneService::getTimeZones());
     $request = $this->getRequest();
     // validate the form
     if ($request->isPost()) {
         // make certain to merge the files info!
         $post = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
         // fill the form with received values
         $userForm->getForm()->setData($post, false);
         // save data
         if ($userForm->getForm()->isValid()) {
             // check the permission and increase permission's actions track
             if (true !== ($result = $this->aclCheckPermission())) {
                 return $result;
             }
             // add a new user
             $result = $this->getModel()->addUser($userForm->getForm()->getData(), LocalizationService::getCurrentLocalization()['language'], true, $this->params()->fromFiles('avatar'));
             if (is_numeric($result)) {
                 $this->flashMessenger()->setNamespace('success')->addMessage($this->getTranslator()->translate('User has been added'));
             } else {
                 $this->flashMessenger()->setNamespace('error')->addMessage($this->getTranslator()->translate($result));
             }
             return $this->redirectTo('users-administration', 'add-user');
         }
     }
     return new ViewModel(['user_form' => $userForm->getForm()]);
 }