Esempio n. 1
0
 public function run($pass_token)
 {
     if (!$pass_token) {
         cmsCore::error404();
     }
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $user = $users_model->getUserByPassToken($pass_token);
     if (!$user) {
         cmsCore::error404();
     }
     $users_model->unlockUser($user['id']);
     $users_model->clearUserPassToken($user['id']);
     cmsEventsManager::hook('user_registered', $user);
     cmsUser::addSessionMessage($this->options['reg_auto_auth'] ? LANG_REG_SUCCESS_VERIFIED_AND_AUTH : LANG_REG_SUCCESS_VERIFIED, 'success');
     // авторизуем пользователя автоматически
     if ($this->options['reg_auto_auth']) {
         $user = cmsEventsManager::hook('user_login', $user);
         cmsUser::sessionSet('user', array('id' => $user['id'], 'groups' => $user['groups'], 'time_zone' => $user['time_zone'], 'perms' => cmsUser::getPermissions($user['groups']), 'is_admin' => $user['is_admin']));
         $update_data = array('ip' => cmsUser::getIp());
         $this->model->update('{users}', $user['id'], $update_data, true);
         cmsEventsManager::hook('auth_login', $user['id']);
     }
     $this->redirect($this->getAuthRedirectUrl($this->options['first_auth_redirect']));
 }
Esempio n. 2
0
File: orfo.php Progetto: mafru/icms2
 public function run()
 {
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $orfo = $this->request->get('orfo');
     $url = $this->request->get('url');
     $comment = $this->request->get('comment', false);
     $author = !cmsUser::isLogged() ? cmsUser::getIp() : cmsUser::get('nickname');
     $form = $this->getForm('orfo');
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $data = $form->parse($this->request, $is_submitted);
         $data['date'] = date('Y-m-d H:i:s');
         $errors = $form->validate($this, $data);
         dump($errors);
         if (!$errors) {
             $this->model->addComplaints($data);
             $messenger = cmsCore::getController('messages');
             $messenger->addRecipient(1);
             $notice = array('content' => sprintf(LANG_COMPLAINTS_ADD_NOTICE, $url, $orfo), 'options' => array('is_closeable' => true));
             $messenger->ignoreNotifyOptions()->sendNoticePM($notice, 'complaints_add');
         }
         cmsTemplate::getInstance()->renderJSON(array('errors' => false, 'callback' => 'formSuccess'));
     }
     $data = array('orfo' => $orfo, 'url' => $url, 'author' => $author, 'comment' => $comment);
     return cmsTemplate::getInstance()->render('orfo', array('form' => $form, 'data' => $data));
 }
Esempio n. 3
0
 public function run()
 {
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $form = $this->getForm('restore');
     $data = array();
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         $data = $form->parse($this->request, $is_submitted);
         $errors = $form->validate($this, $data);
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
         if (!$errors) {
             $user = $users_model->getUserByEmail($data['email']);
             if (!$user) {
                 cmsUser::addSessionMessage(LANG_EMAIL_NOT_FOUND, 'error');
             } else {
                 $pass_token = string_random(32, $user['email']);
                 $users_model->updateUserPassToken($user['id'], $pass_token);
                 $messenger = cmsCore::getController('messages');
                 $to = array('email' => $user['email'], 'name' => $user['nickname']);
                 $letter = array('name' => 'reg_restore');
                 $messenger->sendEmail($to, $letter, array('nickname' => $user['nickname'], 'page_url' => href_to_abs('auth', 'reset', $pass_token), 'valid_until' => html_date(date('d.m.Y H:i', time() + 24 * 3600), true)));
                 cmsUser::addSessionMessage(LANG_TOKEN_SENDED, 'success');
             }
         }
     }
     return cmsTemplate::getInstance()->render('restore', array('data' => $data, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Esempio n. 4
0
 public function run($profile_id)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     $direction = $this->request->get('direction');
     $comment = $this->request->get('comment');
     //
     // Проверяем валидность
     //
     $is_valid = $user->is_logged && cmsUser::isAllowed('users', 'vote_karma') && is_numeric($profile_id) && $user->id != $profile_id && in_array($direction, array('up', 'down')) && (!$this->options['is_karma_comments'] || $comment);
     if (!$is_valid) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     $profile = $this->model->getUser($profile_id);
     if (!$profile || !$this->model->isUserCanVoteKarma($user->id, $profile_id, $this->options['karma_time'])) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     //
     // Сохраняем оценку
     //
     $vote = array('user_id' => $user->id, 'profile_id' => $profile_id, 'points' => $direction == 'up' ? 1 : -1, 'comment' => $comment);
     $vote_id = $this->model->addKarmaVote($vote);
     $value = $profile['karma'] + $vote['points'];
     $result = array('error' => $vote_id ? false : true, 'value' => html_signed_num($value), 'css_class' => html_signed_class($value));
     cmsTemplate::getInstance()->renderJSON($result);
 }
Esempio n. 5
0
 public function run()
 {
     if (cmsUser::isLogged()) {
         return false;
     }
     return array();
 }
Esempio n. 6
0
 public function run()
 {
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $email = $this->request->get('login_email');
     $password = $this->request->get('login_password');
     $remember = (bool) $this->request->get('remember');
     $back_url = $this->request->has('back') ? $this->request->get('back') : false;
     $is_site_offline = !cmsConfig::get('is_site_on');
     if ($this->request->has('submit')) {
         $is_captcha_valid = true;
         if (cmsUser::sessionGet('is_auth_captcha') && $this->options['auth_captcha']) {
             $is_captcha_valid = cmsEventsManager::hook('captcha_validate', $this->request);
         }
         if ($is_captcha_valid) {
             cmsUser::sessionUnset('is_auth_captcha');
             $logged_id = cmsUser::login($email, $password, $remember);
             if ($logged_id) {
                 if ($is_site_offline) {
                     $userSession = cmsUser::sessionGet('user');
                     if (!$userSession['is_admin']) {
                         cmsUser::addSessionMessage(LANG_LOGIN_ADMIN_ONLY, 'error');
                         cmsUser::logout();
                         $this->redirectBack();
                     }
                 }
                 cmsEventsManager::hook('auth_login', $logged_id);
                 $is_back = $this->request->get('is_back');
                 if ($is_back) {
                     $this->redirectBack();
                 }
                 if ($back_url) {
                     $this->redirect($back_url);
                 } else {
                     $this->redirectToHome();
                 }
             }
         }
         if ($this->options['auth_captcha'] && !$is_site_offline) {
             cmsUser::sessionSet('is_auth_captcha', true);
         }
         if ($is_captcha_valid) {
             cmsUser::addSessionMessage(LANG_LOGIN_ERROR, 'error');
             if ($is_site_offline) {
                 $this->redirectBack();
             }
         } else {
             cmsUser::addSessionMessage(LANG_CAPTCHA_ERROR, 'error');
         }
     }
     if ($back_url) {
         cmsUser::addSessionMessage(LANG_LOGIN_REQUIRED, 'error');
     }
     if (cmsUser::sessionGet('is_auth_captcha')) {
         $captcha_html = cmsEventsManager::hook('captcha_html');
     }
     return cmsTemplate::getInstance()->render('login', array('back_url' => $back_url, 'captcha_html' => isset($captcha_html) ? $captcha_html : false));
 }
Esempio n. 7
0
 public function run($friend_id)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     if (!$friend_id) {
         cmsCore::error404();
     }
     if ($user->isFriend($friend_id)) {
         return false;
     }
     $friend = $this->model->getUser($friend_id);
     if (!$friend) {
         cmsCore::error404();
     }
     //
     // Запрос по ссылке из профиля
     //
     if ($this->request->isStandard()) {
         //
         // Если запрос от друга уже существует
         //
         if ($this->model->isFriendshipRequested($friend_id, $user->id)) {
             $this->model->addFriendship($user->id, $friend_id);
             cmsUser::addSessionMessage(sprintf(LANG_USERS_FRIENDS_DONE, $friend['nickname']), 'success');
             $this->sendNoticeAccepted($friend);
             $this->redirectToAction($friend_id);
         }
         //
         // Если запроса от друга не было
         //
         if ($this->request->has('submit')) {
             // подтвержение получено
             $csrf_token = $this->request->get('csrf_token');
             if (!cmsForm::validateCSRFToken($csrf_token)) {
                 cmsCore::error404();
             }
             $this->model->addFriendship($user->id, $friend_id);
             cmsUser::addSessionMessage(LANG_USERS_FRIENDS_SENT);
             $this->sendNoticeRequest($friend);
             $this->redirectToAction($friend_id);
         } else {
             // спрашиваем подтверждение
             return cmsTemplate::getInstance()->render('friend_add', array('user' => $user, 'friend' => $friend));
         }
     }
     //
     // Запрос из уведомления (внутренний)
     //
     if ($this->request->isInternal()) {
         $this->model->addFriendship($user->id, $friend_id);
         $this->sendNoticeAccepted($friend);
         return true;
     }
 }
Esempio n. 8
0
 public function actionUpload()
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if ($this->request->has('submit')) {
         $this->uploadImage();
     }
     return $this->cms_template->renderPlain('upload', array('allowed_extensions' => $this->images_controller->getAllowedExtensions()));
 }
Esempio n. 9
0
 public function actionUpload()
 {
     if (!cmsUser::isLogged()) {
         return $this->cms_template->renderJSON(array('status' => 'error', 'msg' => 'auth error'));
     }
     $result = cmsCore::getController('images')->uploadWithPreset('inline_upload_file', 'wysiwyg_markitup');
     if (!$result['success']) {
         return $this->cms_template->renderJSON(array('status' => 'error', 'msg' => $result['error']));
     }
     return $this->cms_template->renderJSON(array('status' => 'success', 'src' => $result['image']['url']));
 }
Esempio n. 10
0
 public function actionUpload($name)
 {
     if (!cmsUser::isLogged()) {
         return $this->cms_template->renderJSON(array('success' => false, 'error' => 'auth error'));
     }
     $result = $this->cms_uploader->enableRemoteUpload()->upload($name, $this->allowed_extensions);
     if ($result['success']) {
         if (!$this->cms_uploader->isImage($result['path'])) {
             $result['success'] = false;
             $result['error'] = LANG_UPLOAD_ERR_MIME;
         }
     }
     if (!$result['success']) {
         if (!empty($result['path'])) {
             $this->cms_uploader->remove($result['path']);
         }
         return $this->cms_template->renderJSON($result);
     }
     $sizes = $this->request->get('sizes', '');
     if (!empty($sizes) && preg_match('/([a-z0-9_,]+)$/i', $sizes)) {
         $sizes = explode(',', $sizes);
     } else {
         $sizes = array_keys((array) $this->model->getPresetsList());
         $sizes[] = 'original';
     }
     $result['paths'] = array();
     if (in_array('original', $sizes, true)) {
         $result['paths']['original'] = array('path' => $result['url'], 'url' => $this->cms_config->upload_host . '/' . $result['url']);
     }
     $presets = $this->model->orderByList(array(array('by' => 'is_square', 'to' => 'asc'), array('by' => 'width', 'to' => 'desc')))->getPresets();
     foreach ($presets as $p) {
         if (!in_array($p['name'], $sizes, true)) {
             continue;
         }
         $path = $this->cms_uploader->resizeImage($result['path'], array('width' => $p['width'], 'height' => $p['height'], 'is_square' => $p['is_square'], 'quality' => $p['is_watermark'] && $p['wm_image'] ? 100 : $p['quality']));
         if (!$path) {
             continue;
         }
         $image = array('path' => $path, 'url' => $this->cms_config->upload_host . '/' . $path);
         if ($p['is_watermark'] && $p['wm_image']) {
             img_add_watermark($image['path'], $p['wm_image']['original'], $p['wm_origin'], $p['wm_margin'], $p['quality']);
         }
         $result['paths'][$p['name']] = $image;
     }
     if (!in_array('original', $sizes, true)) {
         unlink($result['path']);
     }
     if ($this->request->isInternal()) {
         return $result;
     }
     unset($result['path']);
     return $this->cms_template->renderJSON($result);
 }
Esempio n. 11
0
 /**
  * Все запросы могут быть выполнены только авторизованными и только по аякс
  * @param type $action_name
  */
 public function before($action_name)
 {
     parent::before($action_name);
     if (!$this->request->isInternal()) {
         if (!$this->request->isAjax()) {
             cmsCore::error404();
         }
         if (!cmsUser::isLogged()) {
             cmsCore::error404();
         }
     }
     return true;
 }
Esempio n. 12
0
 public function actionUpload()
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if ($this->request->has('submit')) {
         $this->uploadImage();
     }
     $template = cmsTemplate::getInstance();
     $images_controller = cmsCore::getController('images');
     $html = $template->render('upload', array('allowed_extensions' => $images_controller->getAllowedExtensions()));
     echo $html;
     $this->halt();
 }
Esempio n. 13
0
 public function run($user_id)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     if ($user->id != $user_id && !$user->is_admin) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     $this->model->clearUserStatus($user_id);
     $result = array('error' => false);
     cmsTemplate::getInstance()->renderJSON($result);
 }
Esempio n. 14
0
 public function run($friend_id)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     if (!$friend_id) {
         cmsCore::error404();
     }
     if (!$this->model->isFriendshipExists($user->id, $friend_id)) {
         return false;
     }
     $friend = $this->model->getUser($friend_id);
     if (!$friend) {
         cmsCore::error404();
     }
     //
     // Запрос по ссылке из профиля
     //
     if ($this->request->isStandard()) {
         if ($this->request->has('submit')) {
             // подтвержение получено
             $csrf_token = $this->request->get('csrf_token');
             if (!cmsForm::validateCSRFToken($csrf_token)) {
                 cmsCore::error404();
             }
             $this->model->deleteFriendship($user->id, $friend_id);
             cmsUser::addSessionMessage(sprintf(LANG_USERS_FRIENDS_DELETED, $friend['nickname']));
             $this->sendNoticeDeleted($friend);
             $this->redirectToAction($friend_id);
         } else {
             // спрашиваем подтверждение
             return cmsTemplate::getInstance()->render('friend_delete', array('user' => $user, 'friend' => $friend));
         }
     }
     //
     // Запрос из уведомления (внутренний)
     //
     if ($this->request->isInternal()) {
         $this->model->deleteFriendship($user->id, $friend_id);
         $this->sendNoticeDeleted($friend, true);
         return true;
     }
 }
Esempio n. 15
0
 public function run($item)
 {
     $action = $item['action'];
     $menu_item_id = $item['menu_item_id'];
     if ($action == 'add') {
         return $this->getMenuAddItems($menu_item_id);
     } elseif ($action == 'private_list') {
         if (!cmsUser::isLogged()) {
             return false;
         }
         return $this->getMenuPrivateItems($menu_item_id);
     } else {
         $ctype = $this->model->getContentTypeByName($action);
         if (!$ctype) {
             return false;
         }
         return $this->getMenuCategoriesItems($menu_item_id, $ctype);
     }
 }
Esempio n. 16
0
 public function run($pass_token)
 {
     if (!$pass_token) {
         cmsCore::error404();
     }
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $user = $users_model->getUserByPassToken($pass_token);
     if (!$user) {
         cmsCore::error404();
     }
     $users_model->unlockUser($user['id']);
     $users_model->clearUserPassToken($user['id']);
     cmsEventsManager::hook('user_registered', $user);
     cmsUser::addSessionMessage(LANG_REG_SUCCESS_VERIFIED, 'success');
     $this->redirectToHome();
 }
Esempio n. 17
0
 public function run()
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $user_id = $this->request->get('user_id');
     $content = $this->request->get('content');
     // Проверяем валидность
     if (!is_numeric($user_id)) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     $user = cmsUser::getInstance();
     if ($user->id != $user_id) {
         $result = array('error' => true, 'message' => LANG_ERROR);
         cmsTemplate::getInstance()->renderJSON($result);
     }
     // Вырезаем теги и форматируем
     $content = strip_tags($content);
     if (mb_strlen($content) > 140) {
         $content = mb_substr($content, 0, 140);
     }
     $content = cmsEventsManager::hook('html_filter', $content);
     if (!$content) {
         $result = array('error' => true, 'message' => '');
         cmsTemplate::getInstance()->renderJSON($result);
     }
     // Добавляем запись на стену
     $wall_model = cmsCore::getModel('wall');
     $wall_entry_id = $wall_model->addEntry(array('controller' => 'users', 'profile_type' => 'user', 'profile_id' => $user_id, 'user_id' => $user_id, 'content' => $content, 'content_html' => $content));
     // сохраняем статус
     $status_id = $this->model->addUserStatus(array('user_id' => $user_id, 'content' => $content, 'wall_entry_id' => $wall_entry_id));
     if ($status_id) {
         $wall_model->updateEntryStatusId($wall_entry_id, $status_id);
         cmsCore::getController('activity')->addEntry($this->name, "status", array('subject_title' => $content, 'reply_url' => href_to($this->name, $user_id) . "?wid={$wall_entry_id}&reply=1"));
     }
     $result = array('error' => $status_id ? false : true, 'wall_entry_id' => $wall_entry_id, 'content' => $content);
     cmsTemplate::getInstance()->renderJSON($result);
 }
Esempio n. 18
0
 public function run($id)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if (!$id) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     // Получаем нужную запись
     $profile = $this->model->getUser($id);
     // проверяем наличие доступа
     if ($id != $user->id && !$user->is_admin) {
         cmsCore::error404();
     }
     $template = cmsTemplate::getInstance();
     if (!$template->hasProfileThemesOptions()) {
         cmsCore::error404();
     }
     cmsCore::loadTemplateLanguage($template->getName());
     $form = $template->getProfileOptionsForm();
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     $theme = $profile['theme'];
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $theme = array_merge($theme, $form->parse($this->request, $is_submitted, $theme));
         // Проверям правильность заполнения
         $errors = $form->validate($this, $profile);
         if (!$errors) {
             $profile['theme'] = $theme;
             // Обновляем профиль и редиректим на его просмотр
             $this->model->updateUser($id, $profile);
             $this->redirectTo('users', $id);
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return $template->render('profile_theme', array('id' => $id, 'profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Esempio n. 19
0
 public function getDatasets()
 {
     $datasets = array();
     // Популярные
     if ($this->options['is_ds_popular']) {
         $datasets['popular'] = array('name' => 'popular', 'title' => LANG_GROUPS_DS_POPULAR, 'order' => array('members_count', 'desc'));
     }
     // Все (новые)
     $datasets['all'] = array('name' => 'all', 'title' => LANG_GROUPS_DS_LATEST, 'order' => array('date_pub', 'desc'));
     // Рейтинг
     if ($this->options['is_ds_rating']) {
         $datasets['rating'] = array('name' => 'rating', 'title' => LANG_GROUPS_DS_RATED, 'order' => array('rating', 'desc'));
     }
     // Мои
     if (cmsUser::isLogged()) {
         $datasets['my'] = array('name' => 'my', 'title' => LANG_GROUPS_DS_MY, 'order' => array('title', 'asc'), 'filter' => function ($model, $dset) {
             $user = cmsUser::getInstance();
             return $model->filterByMember($user->id);
         });
     }
     return $datasets;
 }
Esempio n. 20
0
 public function run()
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     if (!$this->request->isAjax()) {
         cmsCore::error404();
     }
     $user_id = $this->request->get('user_id', 0);
     $content = $this->request->get('content', '');
     // Проверяем валидность
     if (!is_numeric($user_id)) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_ERROR));
     }
     if ($this->cms_user->id != $user_id) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => LANG_ERROR));
     }
     // Вырезаем теги и форматируем
     $content = cmsEventsManager::hook('html_filter', strip_tags(trim($content)));
     if (!$content) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => ERR_VALIDATE_REQUIRED));
     }
     $status_content = trim(strip_tags($content));
     // проверяем длину статуса
     if (mb_strlen($status_content) > 140) {
         return $this->cms_template->renderJSON(array('error' => true, 'message' => sprintf(ERR_VALIDATE_MAX_LENGTH, 140)));
     }
     // Добавляем запись на стену
     $wall_model = cmsCore::getModel('wall');
     $wall_entry_id = $wall_model->addEntry(array('controller' => 'users', 'profile_type' => 'user', 'profile_id' => $user_id, 'user_id' => $user_id, 'content' => $content, 'content_html' => $content));
     // сохраняем статус
     $status_id = $this->model->addUserStatus(array('user_id' => $user_id, 'content' => $status_content, 'wall_entry_id' => $wall_entry_id));
     if ($status_id) {
         $wall_model->updateEntryStatusId($wall_entry_id, $status_id);
         cmsCore::getController('activity')->addEntry($this->name, 'status', array('subject_title' => $status_content, 'reply_url' => href_to_rel($this->name, $user_id) . "?wid={$wall_entry_id}&reply=1"));
     }
     return $this->cms_template->renderJSON(array('error' => $status_id ? false : true, 'wall_entry_id' => $wall_entry_id, 'content' => $status_content));
 }
Esempio n. 21
0
            ?>
                            <span class="is_private" title="<?php 
            html(LANG_PRIVACY_PRIVATE);
            ?>
"></span>
                        <?php 
        }
        ?>
                    </div>
                    <div class="details">
                        <span class="date"><?php 
        echo $item['date_diff'];
        ?>
</span>
                        <?php 
        if (!empty($item['reply_url']) && cmsUser::isLogged()) {
            ?>
                            <span class="reply">
                                <a href="<?php 
            echo $item['reply_url'];
            ?>
"><?php 
            echo LANG_REPLY;
            ?>
</a>
                            </span>
                        <?php 
        }
        ?>
                    </div>
                    <?php 
Esempio n. 22
0
 public function run()
 {
     if (cmsUser::isLogged() && !cmsUser::isAdmin()) {
         $this->redirectToHome();
     }
     $users_model = cmsCore::getModel('users');
     $form = $this->getForm('registration');
     //
     // Добавляем поле для кода приглашения,
     // если регистрация доступна только по приглашениям
     //
     if ($this->options['is_reg_invites']) {
         $fieldset_id = $form->addFieldsetToBeginning(LANG_REG_INVITED_ONLY);
         $form->addField($fieldset_id, new fieldString('inv', array('title' => LANG_REG_INVITE_CODE, 'rules' => array(array('required'), array('min_length', 10), array('max_length', 10)))));
     }
     //
     // Добавляем поле выбора группы,
     // при наличии публичных групп
     //
     $public_groups = $users_model->getPublicGroups();
     if ($public_groups) {
         $pb_items = array();
         foreach ($public_groups as $pb) {
             $pb_items[$pb['id']] = $pb['title'];
         }
         $form->addFieldToBeginning('basic', new fieldList('group_id', array('title' => LANG_USER_GROUP, 'items' => $pb_items)));
     }
     //
     // Добавляем в форму обязательные поля профилей
     //
     $content_model = cmsCore::getModel('content');
     $content_model->setTablePrefix('');
     $content_model->orderBy('ordering');
     $fields = $content_model->getRequiredContentFields('users');
     // Разбиваем поля по группам
     $fieldsets = cmsForm::mapFieldsToFieldsets($fields);
     // Добавляем поля в форму
     foreach ($fieldsets as $fieldset) {
         $fieldset_id = $form->addFieldset($fieldset['title']);
         foreach ($fieldset['fields'] as $field) {
             if ($field['is_system']) {
                 continue;
             }
             $form->addField($fieldset_id, $field['handler']);
         }
     }
     $user = array();
     if ($this->request->hasInQuery('inv')) {
         $user['inv'] = $this->request->get('inv');
     }
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         if (!$this->options['is_reg_enabled']) {
             cmsCore::error404();
         }
         $errors = false;
         $is_captcha_valid = true;
         //
         // Проверяем капчу
         //
         if ($this->options['reg_captcha']) {
             $is_captcha_valid = cmsEventsManager::hook('captcha_validate', $this->request);
             if (!$is_captcha_valid) {
                 $errors = true;
                 cmsUser::addSessionMessage(LANG_CAPTCHA_ERROR, 'error');
             }
         }
         //
         // Парсим и валидируем форму
         //
         if (!$errors) {
             $user = $form->parse($this->request, $is_submitted);
             $user['groups'] = array();
             if (!empty($this->options['def_groups'])) {
                 $user['groups'] = $this->options['def_groups'];
             }
             if (isset($user['group_id'])) {
                 if (!in_array($user['group_id'], $user['groups'])) {
                     $user['groups'][] = $user['group_id'];
                 }
             }
             //
             // убираем поля которые не относятся к выбранной пользователем группе
             //
             foreach ($fieldsets as $fieldset) {
                 foreach ($fieldset['fields'] as $field) {
                     if (!$field['groups_edit']) {
                         continue;
                     }
                     if (in_array(0, $field['groups_edit'])) {
                         continue;
                     }
                     if (!in_array($user['group_id'], $field['groups_edit'])) {
                         $form->disableField($field['name']);
                         unset($user[$field['name']]);
                     }
                 }
             }
             $errors = $form->validate($this, $user);
         }
         if (!$errors) {
             //
             // проверяем код приглашения
             //
             if ($this->options['is_reg_invites']) {
                 $invite = $this->model->getInviteByCode($user['inv']);
                 if (!$invite) {
                     $errors['inv'] = LANG_REG_WRONG_INVITE_CODE;
                 } else {
                     if ($this->options['is_invites_strict'] && $invite['email'] != $user['email']) {
                         $errors['inv'] = LANG_REG_WRONG_INVITE_CODE_EMAIL;
                     } else {
                         $user['inviter_id'] = $invite['user_id'];
                     }
                 }
             }
             //
             // проверяем допустимость e-mail, имени и IP
             //
             if (!$this->isEmailAllowed($user['email'])) {
                 $errors['email'] = sprintf(LANG_AUTH_RESTRICTED_EMAIL, $user['email']);
             }
             if (!$this->isNameAllowed($user['nickname'])) {
                 $errors['nickname'] = sprintf(LANG_AUTH_RESTRICTED_NAME, $user['nickname']);
             }
             if (!$this->isIPAllowed(cmsUser::get('ip'))) {
                 cmsUser::addSessionMessage(sprintf(LANG_AUTH_RESTRICTED_IP, cmsUser::get('ip')), 'error');
                 $errors = true;
             }
         }
         if (!$errors) {
             unset($user['inv']);
             //
             // Блокируем пользователя, если включена верификация e-mail
             //
             if ($this->options['verify_email']) {
                 $user = array_merge($user, array('is_locked' => true, 'lock_reason' => LANG_REG_CFG_VERIFY_LOCK_REASON, 'pass_token' => string_random(32, $user['email']), 'date_token' => ''));
             }
             $result = $users_model->addUser($user);
             if ($result['success']) {
                 $user['id'] = $result['id'];
                 cmsUser::addSessionMessage(LANG_REG_SUCCESS, 'success');
                 // отправляем письмо верификации e-mail
                 if ($this->options['verify_email']) {
                     $messenger = cmsCore::getController('messages');
                     $to = array('email' => $user['email'], 'name' => $user['nickname']);
                     $letter = array('name' => 'reg_verify');
                     $messenger->sendEmail($to, $letter, array('nickname' => $user['nickname'], 'page_url' => href_to_abs('auth', 'verify', $user['pass_token']), 'valid_until' => html_date(date('d.m.Y H:i', time() + $this->options['verify_exp'] * 3600), true)));
                     cmsUser::addSessionMessage(sprintf(LANG_REG_SUCCESS_NEED_VERIFY, $user['email']), 'info');
                 } else {
                     cmsEventsManager::hook('user_registered', $user);
                 }
                 $back_url = cmsUser::sessionGet('auth_back_url') ? cmsUser::sessionGet('auth_back_url', true) : false;
                 if ($back_url) {
                     $this->redirect($back_url);
                 } else {
                     $this->redirectToHome();
                 }
             } else {
                 $errors = $result['errors'];
             }
         }
         if ($errors && $is_captcha_valid) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     // Капча
     if ($this->options['reg_captcha']) {
         $captcha_html = cmsEventsManager::hook('captcha_html');
     }
     return cmsTemplate::getInstance()->render('registration', array('user' => $user, 'form' => $form, 'captcha_html' => isset($captcha_html) ? $captcha_html : false, 'errors' => isset($errors) ? $errors : false));
 }
Esempio n. 23
0
 public function run($profile, $do = false)
 {
     if (!cmsUser::isLogged()) {
         cmsCore::error404();
     }
     $user = cmsUser::getInstance();
     // если нужно, передаем управление другому экшену
     if ($do) {
         $this->runAction('profile_edit_' . $do, array($profile) + array_slice($this->params, 2));
         return;
     }
     // проверяем наличие доступа
     if ($profile['id'] != $user->id && !$user->is_admin) {
         cmsCore::error404();
     }
     // Получаем поля
     $content_model = cmsCore::getModel('content');
     $content_model->setTablePrefix('');
     $content_model->orderBy('ordering');
     $fields = $content_model->getContentFields('{users}');
     // Строим форму
     $form = new cmsForm();
     // Разбиваем поля по группам
     $fieldsets = cmsForm::mapFieldsToFieldsets($fields, function ($field, $user) {
         // проверяем что группа пользователя имеет доступ к редактированию этого поля
         if ($field['groups_edit'] && !$user->isInGroups($field['groups_edit'])) {
             return false;
         }
         return true;
     });
     // Добавляем поля в форму
     foreach ($fieldsets as $fieldset) {
         $fieldset_id = $form->addFieldset($fieldset['title']);
         foreach ($fieldset['fields'] as $field) {
             // добавляем поле в форму
             $form->addField($fieldset_id, $field['handler']);
         }
     }
     // Добавляем поле выбора часового пояса
     $config = cmsConfig::getInstance();
     $fieldset_id = $form->addFieldset(LANG_TIME_ZONE);
     $form->addField($fieldset_id, new fieldList('time_zone', array('default' => $config->time_zone, 'generator' => function ($item) {
         return cmsCore::getTimeZones();
     })));
     // Форма отправлена?
     $is_submitted = $this->request->has('submit');
     if ($is_submitted) {
         // Парсим форму и получаем поля записи
         $new = $form->parse($this->request, $is_submitted, $profile);
         $old = $profile;
         $profile = array_merge($profile, $new);
         // Проверям правильность заполнения
         $errors = $form->validate($this, $profile);
         if (!$errors) {
             $is_allowed = cmsEventsManager::hookAll('user_profile_update', $profile, true);
             if ($is_allowed !== true && in_array(false, $is_allowed)) {
                 $errors = true;
             }
         }
         if (!$errors) {
             // Обновляем профиль и редиректим на его просмотр
             $this->model->updateUser($profile['id'], $profile);
             // Отдельно обновляем часовой пояс в сессии
             cmsUser::sessionSet('user_data:time_zone', $profile['time_zone']);
             // Постим уведомление о смене аватара в ленту
             if (!$this->model->isAvatarsEqual($new['avatar'], $old['avatar'])) {
                 $activity_controller = cmsCore::getController('activity');
                 $activity_controller->deleteEntry($this->name, "avatar", $profile['id']);
                 if (!empty($new['avatar'])) {
                     $activity_controller->addEntry($this->name, "avatar", array('user_id' => $profile['id'], 'subject_title' => $profile['nickname'], 'subject_id' => $profile['id'], 'subject_url' => href_to('users', $profile['id']), 'is_private' => 0, 'group_id' => null, 'images' => array(array('url' => href_to('users', $profile['id']), 'src' => html_image_src($new['avatar'], 'normal'))), 'images_count' => 1));
                 }
             }
             $this->redirectTo('users', $profile['id']);
         }
         if ($errors) {
             cmsUser::addSessionMessage(LANG_FORM_ERRORS, 'error');
         }
     }
     return cmsTemplate::getInstance()->render('profile_edit', array('do' => 'edit', 'id' => $profile['id'], 'profile' => $profile, 'form' => $form, 'errors' => isset($errors) ? $errors : false));
 }
Esempio n. 24
0
 public function run()
 {
     if (cmsUser::isLogged()) {
         $this->redirectToHome();
     }
     $email = $this->request->get('login_email', '');
     $password = $this->request->get('login_password', '');
     $remember = (bool) $this->request->get('remember');
     $back_url = $this->request->get('back', '');
     $is_site_offline = !cmsConfig::get('is_site_on');
     $is_submit = $this->request->has('submit');
     if ($is_submit) {
         $is_captcha_valid = true;
         if (cmsUser::sessionGet('is_auth_captcha') && $this->options['auth_captcha']) {
             $is_captcha_valid = cmsEventsManager::hook('captcha_validate', $this->request);
         }
         if ($is_captcha_valid) {
             cmsUser::sessionUnset('is_auth_captcha');
             $logged_id = cmsUser::login($email, $password, $remember);
             if ($logged_id) {
                 if ($is_site_offline) {
                     $userSession = cmsUser::sessionGet('user');
                     if (!$userSession['is_admin']) {
                         cmsUser::addSessionMessage(LANG_LOGIN_ADMIN_ONLY, 'error');
                         cmsUser::logout();
                         $this->redirectBack();
                     }
                 }
                 cmsEventsManager::hook('auth_login', $logged_id);
                 $auth_redirect = $this->options['auth_redirect'];
                 $is_first_auth = cmsUser::getUPS('first_auth', $logged_id);
                 if ($is_first_auth) {
                     $auth_redirect = $this->options['first_auth_redirect'];
                     cmsUser::deleteUPS('first_auth', $logged_id);
                 }
                 if ($back_url) {
                     $this->redirect($back_url);
                 } else {
                     $this->redirect($this->getAuthRedirectUrl($auth_redirect));
                 }
             }
         }
         if ($this->options['auth_captcha'] && !$is_site_offline) {
             cmsUser::sessionSet('is_auth_captcha', true);
         }
         if ($is_captcha_valid) {
             cmsUser::addSessionMessage(LANG_LOGIN_ERROR, 'error');
             if ($is_site_offline) {
                 $this->redirectBack();
             }
         } else {
             cmsUser::addSessionMessage(LANG_CAPTCHA_ERROR, 'error');
         }
         if ($this->options['auth_redirect'] == 'none' || !empty($is_first_auth) && $this->options['first_auth_redirect'] == 'none') {
             if (!$back_url) {
                 $back_url = $this->getBackURL();
             }
         }
     }
     if ($back_url && !$is_submit) {
         cmsUser::addSessionMessage(LANG_LOGIN_REQUIRED, 'error');
     }
     if (cmsUser::sessionGet('is_auth_captcha')) {
         $captcha_html = cmsEventsManager::hook('captcha_html');
     }
     return $this->cms_template->render('login', array('back_url' => $back_url, 'captcha_html' => isset($captcha_html) ? $captcha_html : false));
 }
Esempio n. 25
0
$this->addMainCSS("templates/{$this->name}/css/theme-modal.css");
?>
    <?php 
$this->addMainJS("templates/{$this->name}/js/jquery.js");
?>
    <?php 
$this->addMainJS("templates/{$this->name}/js/jquery-modal.js");
?>
    <?php 
$this->addMainJS("templates/{$this->name}/js/core.js");
?>
    <?php 
$this->addMainJS("templates/{$this->name}/js/modal.js");
?>
    <?php 
if (cmsUser::isLogged()) {
    ?>
        <?php 
    $this->addMainJS("templates/{$this->name}/js/messages.js");
    ?>
    <?php 
}
?>
    <!--[if lt IE 9]>
        <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    <![endif]-->
    <?php 
$this->head();
?>
    <style><?php