OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)

This commit is contained in:
wangruiguo
2026-09-03 18:49:20 +08:00
commit d647428529
3501 changed files with 1988906 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Auth\Services\Auth as AuthService;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
/**
* Keeping the session alive when not active
*
* @Deprecated With laravels new session management we should not need this anymore
*/
class KeepAlive extends Controller
{
private AuthService $authService;
/**
* init - initialize private variables
*/
public function init(AuthService $authService): void
{
$this->authService = $authService;
}
/**
* get - handle get requests
*/
public function get(array $params): Response
{
$userId = session('userdata.id');
$sessionId = session()->getId();
// @TODO: Once we have a session table, check the session is valid in there as well as
// added security layer. If not we can log the user out.
$return = $this->authService->updateUserSessionDB($userId, $sessionId);
$response = ['status' => 'ok'];
if (! $return) {
$response['status'] = 'logout';
}
return new JsonResponse($response);
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Configuration\Environment;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller as FrontcontrollerCore;
use Leantime\Domain\Auth\Services\Auth as AuthService;
use Symfony\Component\HttpFoundation\Response;
class Login extends Controller
{
private AuthService $authService;
private Environment $config;
/**
* init - initialize private variables
*/
public function init(
AuthService $authService,
Environment $config
): void {
$this->authService = $authService;
$this->config = $config;
}
/**
* get - handle get requests
*
*
*
*
* @throws BindingResolutionException
*/
public function get(array $params): Response
{
self::dispatchEvent('beforeAuth', $params);
$return = self::dispatchFilter('beforeAuthHandling', $params);
if ($return instanceof Response) {
return $return;
}
// Guard the type: redirect[]=x arrives as an array, which would TypeError against
// resolveSafeRedirect(?string) and 500 the login page on malformed input.
$rawRedirect = $_GET['redirect'] ?? null;
$redirectUrl = $this->authService->resolveSafeRedirect(is_string($rawRedirect) ? $rawRedirect : null);
$this->tpl->assign('inputPlaceholder', $this->authService->getLoginInputPlaceholder());
$this->tpl->assign('redirectUrl', urlencode($redirectUrl));
$this->tpl->assign('oidcEnabled', $this->config->oidcEnable);
$this->tpl->assign('noLoginForm', $this->authService->shouldHideLoginForm());
return $this->tpl->display('auth.login', 'entry');
}
/**
* post - handle post requests
*
*
*
*
* @throws BindingResolutionException
*/
public function post(array $params): Response
{
if (isset($_POST['username']) === true && isset($_POST['password']) === true) {
// Same array guard as the GET path above — redirectUrl[]=x must not 500 the login POST.
$rawRedirect = $_POST['redirectUrl'] ?? null;
$redirectUrl = $this->authService->resolveSafeRedirect(is_string($rawRedirect) ? $rawRedirect : null);
$username = trim($_POST['username']);
$password = $_POST['password'];
try {
// Allow login interruptions through events
self::dispatch_event('beforeAuthServiceCall', ['post' => $_POST]);
} catch (\Exception $e) {
$this->tpl->setNotification($e->getMessage(), 'error');
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
// If login successful redirect to the correct url to avoid post on reload
if ($this->authService->login($username, $password) === true) {
self::dispatch_event('successfulLogin', ['post' => $_POST]);
if ($this->authService->use2FA()) {
return FrontcontrollerCore::redirect(BASE_URL.'/auth/twoFA');
}
return FrontcontrollerCore::redirect($redirectUrl);
} else {
$this->tpl->setNotification('notifications.username_or_password_incorrect', 'error');
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
} else {
$this->tpl->setNotification('notifications.username_or_password_missing', 'error');
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller as FrontcontrollerCore;
use Leantime\Domain\Auth\Services\Auth as AuthService;
use Symfony\Component\HttpFoundation\Response;
class Logout extends Controller
{
private AuthService $authService;
/**
* init - initialize private variables
*/
public function init(AuthService $authService): void
{
$this->authService = $authService;
}
/**
* get - handle get requests
*/
public function get(array $params): Response
{
$this->authService->logout();
return FrontcontrollerCore::redirect(BASE_URL.'/');
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Laravel\Socialite\Facades\Socialite;
use Leantime\Core\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* Redirects to the OAuth provider for authentication.
*/
class Redirect extends Controller
{
/**
* Redirects to the GitHub OAuth login page.
*
* @param array $params Request parameters
*/
public function get(array $params): Response
{
return Socialite::driver('github')->setScopes(['user:email'])->redirect();
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller as FrontcontrollerCore;
use Leantime\Domain\Auth\Services\Auth as AuthService;
use Symfony\Component\HttpFoundation\Response;
class ResetPw extends Controller
{
private AuthService $authService;
/**
* init - initialize private variables
*/
public function init(
AuthService $authService
): void {
$this->authService = $authService;
}
/**
* get - handle get requests
*
*
*
*
* @throws \Exception
*/
public function get(array $params): Response
{
if ((isset($params['id']) === true && $this->authService->validateResetLink($params['id']))) {
return $this->tpl->display('auth.resetPw', 'entry');
} else {
return $this->tpl->display('auth.requestPwLink', 'entry');
}
}
/**
* post - handle post requests
*
*
*
*
* @throws BindingResolutionException
*/
public function post(array $params): Response
{
if (! isset($_POST['resetPassword'])) {
return FrontcontrollerCore::redirect(BASE_URL.'/auth/resetPw/');
}
if (isset($_POST['username']) === true) {
// Always return success to prevent db attacks checking which email address are in there
$this->authService->generateLinkAndSendEmail($_POST['username']);
$this->tpl->setNotification($this->language->__('notifications.email_was_sent_to_reset'), 'success');
return FrontcontrollerCore::redirect(BASE_URL.'/auth/resetPw/');
}
if (isset($_POST['password']) === true && isset($_POST['password2']) === true) {
$result = $this->authService->resetPassword($_POST['password'], $_POST['password2'], $params['id']);
if ($result === 'success') {
$this->tpl->setNotification(
$this->language->__('notifications.passwords_changed_successfully'),
'success',
'password_changed'
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
if ($result === 'mismatch') {
$this->tpl->setNotification($this->language->__('notification.passwords_dont_match'), 'error');
return FrontcontrollerCore::redirect(BASE_URL.'/auth/resetPw/'.$params['id']);
}
if ($result === 'weak') {
$this->tpl->setNotification(
$this->language->__('notification.password_not_strong_enough'),
'error'
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/resetPw/'.$params['id']);
}
$this->tpl->setNotification(
$this->language->__('notifications.problem_resetting_password'),
'error'
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/resetPw/'.$params['id']);
}
$this->tpl->setNotification(
$this->language->__('notifications.problem_resetting_password'),
'error'
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/resetPw/'.$params['id']);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Leantime\Core\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* Renders the "create personal access token" modal.
*/
class TokenNew extends Controller
{
/**
* Displays the new token form (loaded into a modal via #/auth/tokenNew).
*
* @param array $params Request parameters
*/
public function get(array $params): Response
{
return $this->tpl->displayPartial('auth.tokenNew');
}
}

View File

@@ -0,0 +1,174 @@
<?php
namespace Leantime\Domain\Auth\Controllers;
use Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Controller\Controller;
use Leantime\Core\Controller\Frontcontroller as FrontcontrollerCore;
use Leantime\Core\UI\Theme;
use Leantime\Domain\Auth\Services\Auth as AuthService;
use Leantime\Domain\Auth\Services\Onboarding as OnboardingService;
use Symfony\Component\HttpFoundation\Response;
class UserInvite extends Controller
{
private AuthService $authService;
private OnboardingService $onboardingService;
private Theme $themeCore;
/**
* init - initializes the objects for the class
*
*
* @param AuthService $authService The AuthService object
* @param OnboardingService $onboardingService The Onboarding service object
* @param Theme $theme The Theme object
*
* @throws \Exception
*/
public function init(
AuthService $authService,
OnboardingService $onboardingService,
Theme $theme
): void {
$this->authService = $authService;
$this->onboardingService = $onboardingService;
$this->themeCore = $theme;
}
/**
* get - handle get requests
*
*
*
*
* @throws \Exception
*/
public function get(array $params): Response
{
if (isset($params['id']) === true) {
$inviteId = htmlspecialchars($params['id']);
$user = $this->authService->getUserByInviteLink($params['id']);
if (! $user) {
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
$inviteSettings = $this->onboardingService->getInviteSettings($user);
array_map([$this->tpl, 'assign'], array_keys($inviteSettings), array_values($inviteSettings));
$this->tpl->assign('user', $user);
$this->tpl->assign('themeCore', $this->themeCore);
$this->tpl->assign('inviteId', $inviteId);
if (isset($_GET['step']) && is_numeric($_GET['step'])) {
return $this->tpl->display('auth.userInvite'.$_GET['step'], 'entry');
}
return $this->tpl->display('auth.userInvite', 'entry');
}
return FrontcontrollerCore::redirect(BASE_URL.'/errors/error404');
}
/**
* post - handle post requests
*
*
*
*
* @throws BindingResolutionException
*/
public function post(array $params): Response
{
$invitationId = $params['id'] ?? '';
$userInvite = $this->authService->getUserByInviteLink($invitationId);
if (! $userInvite) {
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
// Step 1
if (isset($_POST['saveAccount']) && isset($_POST['step'])) {
$result = $this->onboardingService->saveAccount(
$userInvite,
$_POST['name'] ?? '',
$_POST['jobTitle'] ?? '',
$_POST['password'] ?? ''
);
if ($result === 'weak') {
$this->tpl->setNotification(
$this->language->__('notification.password_not_strong_enough'),
'error'
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/userInvite/'.$invitationId);
}
if ($result === 'saved') {
return FrontcontrollerCore::redirect(BASE_URL.'/auth/userInvite/'.$invitationId.'?step=2');
} else {
$this->tpl->setNotification(
$this->language->__('notifications.problem_updating_user'),
'error'
);
}
}
if (isset($_POST['step']) && $_POST['step'] == 2) {
$this->onboardingService->saveThemeChoice($userInvite, $_POST['theme'], $_POST['themeFont']);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/userInvite/'.$invitationId.'?step=3');
}
if (isset($_POST['step']) && $_POST['step'] == 3) {
$this->onboardingService->saveColorChoice(
$userInvite,
$_POST['colormode'],
$_POST['colorscheme'] ?? 'themeDefault'
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/userInvite/'.$invitationId.'?step=4');
}
if (isset($_POST['step']) && $_POST['step'] == 4) {
$this->onboardingService->saveSchedule(
$userInvite,
$_POST['daySchedule-workStart'] ?? '',
$_POST['daySchedule-lunch'] ?? '',
$_POST['daySchedule-workEnd'] ?? ''
);
return FrontcontrollerCore::redirect(BASE_URL.'/auth/userInvite/'.$invitationId.'?step=5');
}
if (isset($_POST['step']) && $_POST['step'] == 5) {
$this->tpl->setNotification(
$this->language->__('notifications.you_are_active'),
'success',
'user_activated'
);
$loggedIn = $this->onboardingService->completeOnboarding($userInvite);
if ($loggedIn) {
return FrontcontrollerCore::redirect(BASE_URL.'/dashboard/home');
} else {
return FrontcontrollerCore::redirect(BASE_URL.'/auth/login');
}
}
return FrontcontrollerCore::redirect(BASE_URL.'/auth/userInvite/'.$invitationId);
}
}