예제 #1
0
    /**
     * Installing new database. Use only when auto-creating new site
     */
    public function recreateDefaults()
    {
        // Administrator group
        /** @var AdminUserGroup $group */
        $group = AdminUserGroupRepository::findOneEntityById(1);
        // If no any Admin group - create new empty group
        if (!$group || !$group->getUndeletable() || !$group->getCanSetPermissions() || !$group->getFullAccess()) {
            if ($group) {
                $group->is_superadmin = true;
                $group->setField('undeletable', 1)->setField('can_set_permissions', 1)->setField('structure_permissions', 1)->setFullAccess(1)->save();
            } else {
                // Delete all groups
                $group_collection = new AdminUserGroupRepository();
                $group_collection->deleteObjectCollection();
                // Drop auto-increment value
                $group_collection->alterTableResetAutoIncrement();
                // Create new Group for Admins
                $group = new AdminUserGroup();
                $group->is_superadmin = true;
                $group->loadDataFromArray(['undeletable' => 1, 'can_set_permissions' => 1, 'structure_permissions' => 1, 'full_access' => 1, 'title' => 'Developers']);
                $group->save();
                // Create new Group for Managers
                $group = new AdminUserGroup();
                $group->is_superadmin = true;
                $group->loadDataFromArray(['undeletable' => 0, 'can_set_permissions' => 1, 'structure_permissions' => 1, 'full_access' => 1, 'title' => 'Managers', 'default' => 1]);
                $group->save();
                echo '<br>Default User Group is created.<br>';
            }
        }
        unset($data);
        // Check we have any active Admin
        $users_collection = new AdminUserRepository();
        $users_collection->setWhereActive(1);
        $have_any_user = $users_collection->hasAnyObjectInCollection();
        // Check we have admin as first User
        $users_collection = new AdminUserRepository();
        $users_collection->setWhereActive(1);
        $users_collection->setWhereId(1);
        $users_collection->setWhereGroupId(1);
        $users_collection->setWhereLogin('neTpyceB');
        // Name of vendor repo owner
        $have_default_user = $users_collection->hasAnyObjectInCollection();
        // Recreate default User
        if (!$have_any_user || !$have_default_user) {
            //Remove all Users
            $users_collection = new AdminUserRepository();
            $users_collection->deleteObjectCollection();
            // Reset auto-increment
            $users_collection->alterTableResetAutoIncrement();
            // Create new default Developer
            $user = new AdminUser();
            $user->loadDataFromArray(['group_id' => 1, 'login' => 'neTpyceB', 'password' => $this->generateHash(''), 'active' => 1]);
            $user->save();
            // Create new default Manager
            $user = new AdminUser();
            $user->loadDataFromArray(['group_id' => 2, 'login' => 'manager', 'password' => $this->generateHash(''), 'active' => 1]);
            $user->save();
            echo '<br>Default User "manager" and empty password is created.
			<br>
			Please log in and change password.
			<br>';
        }
    }
예제 #2
0
<?php

defined('INC') or exit;
use TMCms\Admin\Messages;
use TMCms\Admin\Users\Entity\AdminUser;
use TMCms\Log\App;
$user = new AdminUser(USER_ID);
$user->loadDataFromArray($_POST);
$user->save();
App::add('Notes updated');
Messages::sendGreenAlert('Notes updated');
back();
예제 #3
0
    /**
     * Get top page header
     * @return string
     */
    public function getMenuHeaderView()
    {
        if (!defined('USER_ID') || !USER_ID) {
            return '';
        }
        ob_start();
        // Notifications from system
        $notification_repository = new UsersMessageEntityRepository();
        $notification_repository->setWhereToUserId(USER_ID);
        $notification_repository->setWhereFromUserId(0);
        $notification_repository->addOrderByField('ts', true);
        $notification_repository->setWhereSeen(0);
        $total_notifications = $notification_repository->getCountOfObjectsInCollection();
        $notification_repository->setLimit(10);
        $notifications = $notification_repository->getAsArrayOfObjects();
        // Messages from users
        $messages_repository = new UsersMessageEntityRepository();
        $messages_repository->setWhereToUserId(USER_ID);
        $messages_repository->addWhereFieldIsNot('from_user_id', 0);
        $messages_repository->addOrderByField('ts', true);
        $messages_repository->setWhereSeen(0);
        $total_messages = $messages_repository->getCountOfObjectsInCollection();
        $messages_repository->setLimit(10);
        $messages = $messages_repository->getAsArrayOfObjects();
        // Custom notifiers
        // TODO
        $custom_notifiers = [];
        $custom_notifiers[] = $this->getHelpTextsNotifier();
        // Logo image and link
        $logo = '';
        if (array_key_exists('logo', Configuration::getInstance()->get('cms'))) {
            $logo = Configuration::getInstance()->get('cms')['logo'];
        }
        $logo_link = DIR_CMS_URL;
        if (array_key_exists('logo_link', Configuration::getInstance()->get('cms'))) {
            $logo_link = Configuration::getInstance()->get('cms')['logo_link'];
        }
        $user_avatar = Users::getInstance()->getUserData('avatar');
        if (!$user_avatar) {
            $user_avatar = '/vendor/devp-eu/tmcms-core/src/assets/cms/layout/img/avatar.png';
        }
        $languages = AdminLanguages::getPairs();
        $current_language = Users::getInstance()->getUserLng();
        ?>
        <div class="page-header-inner">
            <?php 
        if ($logo) {
            ?>
                <div class="page-logo">
                    <a href="<?php 
            echo $logo_link;
            ?>
">
                        <img src="<?php 
            echo $logo;
            ?>
" alt="logo" class="logo-default">
                    </a>
                    <div class="menu-toggler sidebar-toggler"></div>
                </div>
            <?php 
        }
        ?>
            <a href="javascript:;" class="menu-toggler responsive-toggler" data-toggle="collapse" data-target=".navbar-collapse"></a>
            <div class="top-menu">
                <ul class="nav navbar-nav pull-right">
                    <li class="dropdown dropdown-extended dropdown-home" id="header_home_bar">
                        <a href="/" target="_blank" class="dropdown-toggle" data-hover="dropdown" data-close-others="true">
                            <i class="icon-home"></i>
                        </a>
                    </li>
                    <?php 
        if (count($languages) > 1) {
            ?>
                        <li class="dropdown dropdown-language">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                <img alt="" src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?php 
            echo LNG;
            ?>
.png">
                                <span class="langname"><?php 
            echo strtoupper(LNG);
            ?>
 </span>
                                <i class="fa fa-angle-down"></i>
                            </a>
                            <ul class="dropdown-menu">
                                <?php 
            foreach ($languages as $k => $v) {
                if ($k == LNG) {
                    continue;
                }
                ?>
                                <li>
                                    <a href="?p=users&do=_change_lng&lng=<?php 
                echo $k;
                ?>
">
                                        <img alt="" src="/vendor/devp-eu/tmcms-core/src/assets/cms/img/flags/<?php 
                echo $k;
                ?>
.png"> <?php 
                echo $v;
                ?>
                                    </a>
                                </li>
                                <?php 
            }
            ?>
                            </ul>
                        </li>
                    <?php 
        }
        ?>
                    <?php 
        if ($notifications) {
            ?>
                        <li class="dropdown dropdown-extended dropdown-notification" id="header_notification_bar">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                <i class="icon-bell"></i>
                                <span class="badge badge-default"><?php 
            echo count($notifications);
            ?>
</span>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <p>
                                        You have <?php 
            echo $total_notifications;
            ?>
 new notifications
                                    </p>
                                </li>
                                <li>
                                    <ul class="dropdown-menu-list scroller" style="height: 250px;">
                                        <?php 
            foreach ($notifications as $k => $message) {
                /** @var UsersMessageEntity $message */
                ?>
                                            <li>
                                                <a href="#">
                                                    <span class="label label-sm label-icon label-warning">
                                                        <i class="fa fa-bell-o"></i>
                                                    </span>
                                                    <?php 
                echo $message->getMessage();
                ?>
                                                    <span class="time">
                                                        <?php 
                echo Converter::getTimeFromEventAgo($message->getTs());
                ?>
                                                    </span>
                                                </a>
                                            </li>
                                        <?php 
            }
            ?>
                                    </ul>
                                </li>
                                <li class="external">
                                    <a href="?p=home&do=notifications">
                                        See all notifications <i class="m-icon-swapright"></i>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    <?php 
        }
        ?>
                    <?php 
        if ($messages) {
            ?>
                        <li class="dropdown dropdown-extended dropdown-inbox" id="header_inbox_bar">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                                <i class="icon-envelope-open"></i>
                                <span class="badge badge-default"><?php 
            echo count($messages);
            ?>
</span>
                            </a>
                            <ul class="dropdown-menu">
                                <li>
                                    <p>
                                        You have <?php 
            echo $total_messages;
            ?>
 new messages
                                    </p>
                                </li>
                                <li>
                                    <ul class="dropdown-menu-list scroller" style="height: 250px;">
                                        <?php 
            foreach ($notifications as $k => $message) {
                /** @var UsersMessageEntity $message */
                $user = new AdminUser($message->getFromUserId());
                $avatar = $user->getAvatar();
                ?>
                                            <li>
                                                <a href="?p=users&do=chat&user_id=2">
                                                    <?php 
                if ($avatar) {
                    ?>
                                                        <span class="photo">
                                                           <img src="<?php 
                    echo $avatar;
                    ?>
" alt="" style="height=40px">
                                                        </span>
                                                    <?php 
                }
                ?>
                                                    <span class="subject">
                                                        <span class="from"><?php 
                echo $user->getName();
                ?>
</span>
                                                        <span class="time"><?php 
                echo Converter::getTimeFromEventAgo($message->getTs());
                ?>
</span>
                                                    </span>
                                                    <span class="message"><?php 
                echo Converter::cutLongStrings($message->getMessage());
                ?>
</span>
                                                </a>
                                            </li>
                                        <?php 
            }
            ?>
                                    </ul>
                                </li>
                                <li class="external">
                                    <a href="?p=users&do=chat">
                                        See all messages <i class="m-icon-swapright"></i>
                                    </a>
                                </li>
                            </ul>
                        </li>
                    <?php 
        }
        ?>
                    <?php 
        if ($custom_notifiers) {
            ?>
                        <?php 
            echo implode('', $custom_notifiers);
            ?>
                    <?php 
        }
        ?>
                    <li class="dropdown dropdown-user">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-close-others="true">
                            <img alt="" class="img-circle" src="<?php 
        echo $user_avatar;
        ?>
" style="height: 29px;">
                            <span class="username"><?php 
        echo Users::getInstance()->getUserData('name');
        ?>
</span>
                            <i class="fa fa-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="?p=users&do=users_edit&id=<?php 
        echo USER_ID;
        ?>
">
                                    <i class="icon-user"></i> My Profile
                                </a>
                            </li>
                            <li>
                                <a href="?p=home&do=notifications">
                                    <i class="icon-envelope-open"></i>My notifications
                                    <span class="badge badge-danger"> <?php 
        echo count($notifications);
        ?>
</span>
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="#" onclick="clipboard_forms.copy_page_forms(); return false;">
                                    <i class="icon-cloud-download"></i>Copy form data
                                </a>
                            </li>
                            <li>
                                <a href="#" onclick="clipboard_forms.paste_page_forms(); return false;">
                                    <i class="icon-cloud-upload"></i>Paste form data
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="?p=home&do=_exit" onclick="return confirm('<?php 
        echo __('Are you sure?');
        ?>
');">
                                    <i class="icon-key"></i> Log Out
                                </a>
                            </li>
                        </ul>
                    </li>
                    <?php 
        // TODO right panel
        ?>
<!--                    <li class="dropdown dropdown-quick-sidebar-toggler">-->
<!--                        <a href="javascript:;" class="dropdown-toggle">-->
<!--                            <i class="icon-logout"></i>-->
<!--                        </a>-->
<!--                    </li>-->
                </ul>
            </div>
        </div>
        <?php 
        return ob_get_clean();
    }
예제 #4
0
 public function _register()
 {
     if (!$_POST || !isset($_POST['login'], $_POST['email'], $_POST['password']) || trim($_POST['login']) == '') {
         sleep(5);
         go('/');
     }
     // Check user exists
     $user_collection = new AdminUserRepository();
     $user_collection->setWhereLogin($_POST['login']);
     if ($user_collection->hasAnyObjectInCollection()) {
         error('User with this login already exists');
     }
     // Create new user
     $default_group_id = 1;
     $group_collection = new AdminUserGroupRepository();
     $group_collection->setWhereDefault(true);
     /** @var AdminUser $user */
     $group = $group_collection->getFirstObjectFromCollection();
     if ($group) {
         $default_group_id = $group->getId();
     }
     $user = new AdminUser();
     $user->loadDataFromArray($_POST);
     if ($user->getEmail() && !Verify::email($user->getEmail())) {
         error('Wrong email');
     }
     $user->setGroupId($default_group_id);
     $user->setPassword($_POST['password']);
     $user->save();
     // TODO send email to new user with confirmation link
     // TODO make "restore password"
     go(SELF, ['registered' => 1]);
 }