예제 #1
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();
예제 #2
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>';
        }
    }
예제 #3
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]);
 }