OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
79
app/Domain/Users/Controllers/Import.php
Normal file
79
app/Domain/Users/Controllers/Import.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/* Not production ready yet. Prepping for future version */
|
||||
|
||||
namespace Leantime\Domain\Users\Controllers;
|
||||
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\Controller;
|
||||
use Leantime\Domain\Auth\Models\Roles;
|
||||
use Leantime\Domain\Ldap\Services\Ldap as LdapService;
|
||||
use Leantime\Domain\Users\Permissions\UsersPermissions;
|
||||
use Leantime\Domain\Users\Services\Users as UserService;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class Import extends Controller
|
||||
{
|
||||
private UserService $userService;
|
||||
|
||||
private LdapService $ldapService;
|
||||
|
||||
public function init(UserService $userService, LdapService $ldapService): void
|
||||
{
|
||||
$this->userService = $userService;
|
||||
$this->ldapService = $ldapService;
|
||||
|
||||
if (! session()->exists('tmp')) {
|
||||
session(['tmp' => []]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[RequiresPermission(UsersPermissions::IMPORT, global: true)]
|
||||
public function get(): Response
|
||||
{
|
||||
$this->tpl->assign('allUsers', $this->userService->getAll());
|
||||
$this->tpl->assign('admin', true);
|
||||
$this->tpl->assign('roles', Roles::getRoles());
|
||||
|
||||
if (session()->exists('tmp.ldapUsers') && count(session('tmp.ldapUsers')) > 0) {
|
||||
$this->tpl->assign('allLdapUsers', session('tmp.ldapUsers'));
|
||||
$this->tpl->assign('confirmUsers', true);
|
||||
}
|
||||
|
||||
return $this->tpl->displayPartial('users.importLdapDialog');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
#[RequiresPermission(UsersPermissions::IMPORT, global: true)]
|
||||
public function post($params): Response
|
||||
{
|
||||
// Password Submit to connect to ldap and retrieve users. Sets tmp session var
|
||||
if (isset($params['pwSubmit'])) {
|
||||
$bindUsername = $this->ldapService->extractLdapFromUsername(session('userdata.mail'));
|
||||
$members = $this->userService->fetchLdapMembers($bindUsername, $params['password']);
|
||||
|
||||
if ($members !== false) {
|
||||
session(['tmp.ldapUsers' => $members]);
|
||||
$this->tpl->assign('allLdapUsers', session('tmp.ldapUsers'));
|
||||
$this->tpl->assign('confirmUsers', true);
|
||||
} else {
|
||||
$this->tpl->setNotification($this->language->__('notifications.username_or_password_incorrect'), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// Import/Update User Post
|
||||
if (isset($params['importSubmit'])) {
|
||||
if (is_array($params['users'])) {
|
||||
$this->userService->importSelectedLdapUsers(session('tmp.ldapUsers'), $params['users']);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->tpl->displayPartial('users.importLdapDialog');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user