mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2025-01-22 12:44:25 +00:00
make common initUser method
This commit is contained in:
parent
28f21d09c6
commit
c1c5c7fa59
@ -35,22 +35,11 @@ class ArticleController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
return $this->render('default/article/info.html.twig', [
|
||||
'title' => 'test'
|
||||
@ -76,22 +65,11 @@ class ArticleController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -270,4 +248,31 @@ class ArticleController extends AbstractController
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function initUser(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): ?\App\Entity\User
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
@ -32,22 +32,11 @@ class SearchController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
$article = $request->query->get('article') ? (int) $request->query->get('article') : 1;
|
||||
|
||||
@ -160,4 +149,31 @@ class SearchController extends AbstractController
|
||||
'type' => $type,
|
||||
]);
|
||||
}
|
||||
|
||||
private function initUser(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): ?\App\Entity\User
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
@ -37,22 +37,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
@ -198,22 +187,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -372,22 +350,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -578,22 +545,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
@ -675,22 +631,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
@ -765,22 +710,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -941,22 +875,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
@ -1038,22 +961,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Init torrent
|
||||
if (!$torrent = $torrentService->getTorrent($request->get('torrentId')))
|
||||
@ -1122,22 +1034,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -1211,22 +1112,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -1327,22 +1217,11 @@ class TorrentController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -1414,4 +1293,31 @@ class TorrentController extends AbstractController
|
||||
// Render response
|
||||
return new Response(); // @TODO
|
||||
}
|
||||
|
||||
private function initUser(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): ?\App\Entity\User
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
@ -24,22 +24,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
return $this->redirectToRoute(
|
||||
'user_dashboard',
|
||||
@ -55,10 +44,16 @@ class UserController extends AbstractController
|
||||
)]
|
||||
public function index(
|
||||
Request $request,
|
||||
ActivityService $activityService,
|
||||
UserService $userService
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): Response
|
||||
{
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
return $this->render(
|
||||
'default/user/dashboard.html.twig',
|
||||
[
|
||||
@ -84,22 +79,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
// Process post request
|
||||
if ($request->isMethod('post'))
|
||||
@ -198,22 +182,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -284,22 +257,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isStatus())
|
||||
{
|
||||
@ -371,22 +333,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
@ -456,22 +407,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
@ -543,22 +483,11 @@ class UserController extends AbstractController
|
||||
): Response
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
$user = $this->initUser(
|
||||
$request,
|
||||
$userService,
|
||||
$activityService
|
||||
);
|
||||
|
||||
if (!$user->isModerator())
|
||||
{
|
||||
@ -643,4 +572,31 @@ class UserController extends AbstractController
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function initUser(
|
||||
Request $request,
|
||||
UserService $userService,
|
||||
ActivityService $activityService
|
||||
): ?\App\Entity\User
|
||||
{
|
||||
// Init user
|
||||
if (!$user = $userService->findUserByAddress($request->getClientIp()))
|
||||
{
|
||||
$user = $userService->addUser(
|
||||
$request->getClientIp(),
|
||||
time(),
|
||||
$this->getParameter('app.locale'),
|
||||
explode('|', $this->getParameter('app.locales')),
|
||||
$this->getParameter('app.theme')
|
||||
);
|
||||
|
||||
// Add user join event
|
||||
$activityService->addEventUserAdd(
|
||||
$user->getId(),
|
||||
time()
|
||||
);
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user