commit
64837f5077
@ -0,0 +1,34 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Application\Migrations\Schema\V200; |
||||
|
||||
use Application\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
/** |
||||
* Class Version20180904175500 |
||||
* |
||||
* Add foreign key from message |
||||
* |
||||
* @package Application\Migrations\Schema\V200 |
||||
*/ |
||||
class Version20180904175500 extends AbstractMigrationChamilo |
||||
{ |
||||
/** |
||||
* @param Schema $schema |
||||
*/ |
||||
public function up(Schema $schema) |
||||
{ |
||||
$this->addSql('CREATE INDEX IDX_B68FF524537A1329 ON message_attachment (message_id)'); |
||||
$this->addSql('ALTER TABLE message_attachment CHANGE message_id message_id BIGINT NOT NULL'); |
||||
$this->addSql('ALTER TABLE message_attachment ADD CONSTRAINT FK_B68FF524537A1329 FOREIGN KEY (message_id) REFERENCES message (id)'); |
||||
} |
||||
|
||||
/** |
||||
* @param Schema $schema |
||||
*/ |
||||
public function down(Schema $schema) |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
overblog_graphql: |
||||
definitions: |
||||
schema: |
||||
query: Query |
||||
mutation: Mutation |
||||
mappings: |
||||
auto_discover: false |
||||
types: |
||||
# - |
||||
# type: yaml |
||||
# dir: "%kernel.project_dir%/config/graphql/types" |
||||
# suffix: ~ |
||||
- |
||||
type: yaml |
||||
dir: "%kernel.root_dir%/ApiBundle/GraphQL/Type" |
@ -0,0 +1,3 @@ |
||||
overblog_graphql_endpoint: |
||||
resource: "@OverblogGraphQLBundle/Resources/config/routing/graphql.yml" |
||||
prefix: /graphql |
@ -1,8 +0,0 @@ |
||||
Date plugin |
||||
=== |
||||
|
||||
This plugin is more of a demo and a plugin example than a real, functional plugin. |
||||
|
||||
It will show the current date in an area of your choice. |
||||
|
||||
The .act.php and .dsp.php files are just remains of a time where we didn't use the Twig templating system. |
@ -1,22 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Action script for example date plugin. |
||||
* |
||||
* @package chamilo.plugin.date |
||||
*/ |
||||
/** |
||||
* Initialization. |
||||
*/ |
||||
$convert_lang_to_code = [ |
||||
"english" => "en_US", |
||||
"french" => "fr_BE", |
||||
"dutch" => "nl_NL", |
||||
"german" => "de_DE", |
||||
"japanese" => "ja_JP", |
||||
"danish" => "da_DK", |
||||
]; |
||||
if (!empty($_SESSION['user_language_choice']) && !empty($convert_lang_to_code[$_SESSION['user_language_choice']])) { |
||||
$code = $convert_lang_to_code[$_SESSION['user_language_choice']]; |
||||
$locale = setlocale(LC_TIME, $code); |
||||
} |
||||
$date = strftime('%c'); |
@ -1,10 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Display script for example date plugin. |
||||
* |
||||
* @package chamilo.plugin.date |
||||
*/ |
||||
/** |
||||
* Display. |
||||
*/ |
||||
echo '<div class="well">'.strip_tags($date).'</div>'; |
@ -1,11 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Controller for example date plugin. |
||||
* |
||||
* @package chamilo.plugin.date |
||||
*/ |
||||
/** |
||||
* Code. |
||||
*/ |
||||
require 'index.act.php'; |
||||
require 'index.dsp.php'; |
@ -1,20 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* This script is a configuration file for the date plugin. You can use it as a master for other platform plugins (course plugins are slightly different). |
||||
* These settings will be used in the administration interface for plugins (Chamilo configuration settings->Plugins). |
||||
* |
||||
* @package chamilo.plugin |
||||
* |
||||
* @author Yannick Warnier <ywarnier@beeznest.org> |
||||
*/ |
||||
/** |
||||
* Plugin details (must be present). |
||||
*/ |
||||
//the plugin title |
||||
$plugin_info['title'] = 'Date'; |
||||
//the comments that go with the plugin |
||||
$plugin_info['comment'] = "Multinational date display"; |
||||
//the plugin version |
||||
$plugin_info['version'] = '1.0'; |
||||
//the plugin author |
||||
$plugin_info['author'] = 'Yannick Warnier'; |
@ -1,10 +0,0 @@ |
||||
<?php |
||||
/** |
||||
* Controller for example date plugin. |
||||
* |
||||
* @package chamilo.plugin.date |
||||
*/ |
||||
/** |
||||
* Code. |
||||
*/ |
||||
require 'index.php'; |
@ -0,0 +1,109 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL; |
||||
|
||||
use Chamilo\CoreBundle\Framework\Container; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Firebase\JWT\JWT; |
||||
|
||||
/** |
||||
* Class Auth. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL |
||||
*/ |
||||
class Auth |
||||
{ |
||||
/** |
||||
* @param string $username |
||||
* @param string $password |
||||
* |
||||
* @throws \Exception |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getUserToken($username, $password): string |
||||
{ |
||||
/** @var User $user */ |
||||
$user = Container::getUserManager()->findUserBy(['username' => $username]); |
||||
|
||||
if (!$user) { |
||||
throw new \Exception(get_lang('NoUser')); |
||||
} |
||||
|
||||
$encoder = Container::$container->get('chamilo_user.security.encoder'); |
||||
$isValid = $encoder->isPasswordValid( |
||||
$user->getPassword(), |
||||
$password, |
||||
$user->getSalt() |
||||
); |
||||
|
||||
if (!$isValid) { |
||||
throw new \Exception(get_lang('InvalidId')); |
||||
} |
||||
|
||||
return self::generateToken($user->getId()); |
||||
} |
||||
|
||||
/** |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @throws \Exception |
||||
*/ |
||||
public static function checkAuthorization(\ArrayObject $context): void |
||||
{ |
||||
$header = Container::getRequest()->headers->get('Authorization'); |
||||
$token = str_replace(['Bearer ', 'bearer '], '', $header); |
||||
|
||||
if (empty($token)) { |
||||
throw new \Exception(get_lang('NotAllowed')); |
||||
} |
||||
|
||||
$tokenData = Auth::getTokenData($token); |
||||
|
||||
/** @var User $user */ |
||||
$user = Container::getUserManager()->find($tokenData['user']); |
||||
|
||||
if (!$user) { |
||||
throw new \Exception(get_lang('NotAllowed')); |
||||
} |
||||
|
||||
$context->offsetSet('user', $user); |
||||
} |
||||
|
||||
/** |
||||
* @param int $userId |
||||
* |
||||
* @return string |
||||
*/ |
||||
private static function generateToken($userId): string |
||||
{ |
||||
$secret = Container::$container->getParameter('secret'); |
||||
$time = time(); |
||||
|
||||
$payload = [ |
||||
'iat' => $time, |
||||
'exp' => $time + (60 * 60 * 24), |
||||
'data' => [ |
||||
'user' => $userId, |
||||
], |
||||
]; |
||||
|
||||
return JWT::encode($payload, $secret, 'HS384'); |
||||
} |
||||
|
||||
/** |
||||
* @param string $token |
||||
* |
||||
* @return array |
||||
*/ |
||||
private static function getTokenData($token): array |
||||
{ |
||||
$secret = Container::$container->getParameter('secret'); |
||||
$jwt = JWT::decode($token, $secret, ['HS384']); |
||||
|
||||
$data = (array) $jwt->data; |
||||
|
||||
return $data; |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Mutation; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\Auth; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\MutationInterface; |
||||
use Overblog\GraphQLBundle\Error\UserError; |
||||
|
||||
/** |
||||
* Class RootMutation. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Mutation |
||||
*/ |
||||
class RootMutation implements MutationInterface, AliasedInterface |
||||
{ |
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases() |
||||
{ |
||||
return [ |
||||
'mutationAuthenticate' => 'authenticate', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Argument $args |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function mutationAuthenticate(Argument $args) |
||||
{ |
||||
try { |
||||
$token = Auth::getUserToken($args['username'], $args['password']); |
||||
} catch (\Exception $exception) { |
||||
throw new UserError(get_lang('NotAllowed')); |
||||
} |
||||
|
||||
return [ |
||||
'token' => $token, |
||||
]; |
||||
} |
||||
} |
@ -0,0 +1,68 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\CoreBundle\Entity\Message; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
|
||||
/** |
||||
* Class MessageResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class MessageResolver implements ResolverInterface, AliasedInterface |
||||
{ |
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases() |
||||
{ |
||||
return [ |
||||
'resolveSender' => 'message_sender', |
||||
'resolveExcerpt' => 'message_excerpt', |
||||
'resolveHasAttachments' => 'message_has_attachments', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Message $message |
||||
* |
||||
* @return \Chamilo\UserBundle\Entity\User |
||||
*/ |
||||
public function resolveSender(Message $message) |
||||
{ |
||||
return $message->getUserSender(); |
||||
} |
||||
|
||||
/** |
||||
* @param Message $message |
||||
* @param int $length |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function resolveExcerpt($message, $length = 50) |
||||
{ |
||||
$striped = strip_tags($message->getContent()); |
||||
$replaced = str_replace(["\r\n", "\n"], ' ', $striped); |
||||
$trimmed = trim($replaced); |
||||
|
||||
return api_trunc_str($trimmed, $length); |
||||
} |
||||
|
||||
/** |
||||
* @param Message $message |
||||
* |
||||
* @return bool |
||||
*/ |
||||
public function resolveHasAttachments(Message $message) |
||||
{ |
||||
return $message->getAttachments()->count() > 0; |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\Auth; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Overblog\GraphQLBundle\Error\UserError; |
||||
|
||||
/** |
||||
* Class RootResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class RootResolver implements ResolverInterface, AliasedInterface |
||||
{ |
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases() |
||||
{ |
||||
return [ |
||||
'resolverViewer' => 'viewer', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return User |
||||
*/ |
||||
public function resolverViewer(\ArrayObject $context) |
||||
{ |
||||
try { |
||||
Auth::checkAuthorization($context); |
||||
} catch (\Exception $exception) { |
||||
throw new UserError($exception->getMessage()); |
||||
} |
||||
|
||||
/** @var User $user */ |
||||
$user = $context->offsetGet('user'); |
||||
|
||||
return $user; |
||||
} |
||||
} |
@ -0,0 +1,75 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\CoreBundle\Framework\Container; |
||||
use Chamilo\CoreBundle\Repository\MessageRepository; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
|
||||
/** |
||||
* Class UserResolver. |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class UserResolver implements ResolverInterface, AliasedInterface |
||||
{ |
||||
public const IMAGE_SIZE_TINY = 16; |
||||
public const IMAGE_SIZE_SMALL = 32; |
||||
public const IMAGE_SIZE_MEDIUM = 64; |
||||
public const IMAGE_SIZE_BIG = 128; |
||||
|
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases(): array |
||||
{ |
||||
return [ |
||||
'resolveUserPicture' => 'user_picture', |
||||
'resolveUserMessages' => 'user_messages', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param int $size |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function resolveUserPicture($size, \ArrayObject $context): string |
||||
{ |
||||
/** @var User $user */ |
||||
$user = $context->offsetGet('user'); |
||||
|
||||
if (!$user) { |
||||
return null; |
||||
} |
||||
|
||||
$path = $user->getAvatarOrAnonymous((int) $size); |
||||
$url = Container::getAsset()->getUrl($path); |
||||
|
||||
return $url; |
||||
} |
||||
|
||||
/** |
||||
* @param User $user |
||||
* @param int $lastId |
||||
* |
||||
* @return array |
||||
*/ |
||||
public function resolveUserMessages(User $user, $lastId = 0): array |
||||
{ |
||||
/** @var MessageRepository $messageRepo */ |
||||
$messageRepo = Container::getEntityManager()->getRepository('ChamiloCoreBundle:Message'); |
||||
$messages = $messageRepo->getFromLastOneReceived($user, (int) $lastId); |
||||
|
||||
return $messages; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
UserStatus: |
||||
type: enum |
||||
config: |
||||
description: "One of the statuses for the user." |
||||
values: |
||||
TEACHER: |
||||
description: "Global status of a user: Course Manager." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::TEACHER")' |
||||
SESSION_ADMIN: |
||||
description: "Global status of a user: Session Admin." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::SESSION_ADMIN")' |
||||
DRH: |
||||
description: "Global status of a user: Human Ressource Manager." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::DRH")' |
||||
STUDENT: |
||||
description: "Global status of a user: Student." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::STUDENT")' |
||||
|
||||
UserImageSize: |
||||
type: enum |
||||
config: |
||||
description: 'One of the sizes for the user picture.' |
||||
values: |
||||
SIZE_TINY: |
||||
description: 'Image in small size: 16px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_TINY")' |
||||
SIZE_SMALL: |
||||
description: 'Image in small size: 32px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_SMALL")' |
||||
SIZE_MEDIUM: |
||||
description: 'Image in small size: 64px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_MEDIUM")' |
||||
SIZE_BIG: |
||||
description: 'Image in small size: 128px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_BIG")' |
@ -0,0 +1,21 @@ |
||||
Mutation: |
||||
type: object |
||||
config: |
||||
fields: |
||||
authenticate: |
||||
description: "Authenticate user." |
||||
type: "AuthenticatePayload!" |
||||
args: |
||||
username: |
||||
type: "String!" |
||||
password: |
||||
type: "String!" |
||||
resolve: "@=mutation('authenticate', [args])" |
||||
|
||||
AuthenticatePayload: |
||||
type: object |
||||
config: |
||||
fields: |
||||
token: |
||||
description: "Authorization token." |
||||
type: "String!" |
@ -0,0 +1,75 @@ |
||||
Query: |
||||
type: object |
||||
config: |
||||
description: "GraphQL queries." |
||||
fields: |
||||
viewer: |
||||
description: "A registered user on the platform." |
||||
type: "User" |
||||
resolve: "@=resolver('viewer', [context])" |
||||
|
||||
User: |
||||
type: object |
||||
config: |
||||
description: "Registered user." |
||||
fields: |
||||
id: |
||||
description: "The unique ID of the user." |
||||
type: "Int" |
||||
firstname: |
||||
type: "String" |
||||
lastname: |
||||
type: "String" |
||||
username: |
||||
type: "String" |
||||
email: |
||||
type: "String" |
||||
officialCode: |
||||
type: "String" |
||||
status: |
||||
type: "UserStatus" |
||||
picture: |
||||
type: "String" |
||||
args: |
||||
size: |
||||
type: "UserImageSize" |
||||
defaultValue: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_SMALL")' |
||||
resolve: "@=resolver('user_picture', [args['size'], context])" |
||||
messages: |
||||
description: 'Received messages for the user.' |
||||
type: '[UserMessage]' |
||||
args: |
||||
lastId: |
||||
description: 'Last received by the app message ID.' |
||||
type: 'Int' |
||||
defaultValue: 0 |
||||
resolve: "@=resolver('user_messages', [value, args['lastId']])" |
||||
|
||||
UserMessage: |
||||
type: object |
||||
config: |
||||
description: 'Received message by user.' |
||||
fields: |
||||
id: |
||||
description: 'The unique ID of the message.' |
||||
type: 'Int' |
||||
title: |
||||
type: 'String' |
||||
content: |
||||
type: 'String' |
||||
sender: |
||||
type: 'User' |
||||
resolve: "@=resolver('message_sender', [value])" |
||||
sendDate: |
||||
type: 'String' |
||||
excerpt: |
||||
type: 'String' |
||||
args: |
||||
length: |
||||
description: 'The approximate desired length. 50 chars by default.' |
||||
type: 'Int' |
||||
defaultValue: 50 |
||||
resolve: "@=resolver('message_excerpt', [value, args['length']])" |
||||
hasAttachments: |
||||
type: 'Boolean' |
||||
resolve: "@=resolver('message_has_attachments', [value])" |
@ -1,125 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\EventListener; |
||||
|
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Symfony\Component\DependencyInjection\ContainerInterface; |
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
||||
use Symfony\Component\HttpFoundation\RedirectResponse; |
||||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
||||
use Symfony\Component\HttpKernel\KernelEvents; |
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
||||
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; |
||||
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; |
||||
|
||||
/** |
||||
* Class LegacyLoginListener. |
||||
* File not needed the real listener is LegacyListener. |
||||
* |
||||
* @deprecated use LegacyListener |
||||
* |
||||
* @package Chamilo\CoreBundle\EventListener |
||||
*/ |
||||
class LegacyLoginListener implements EventSubscriberInterface |
||||
{ |
||||
/** @var ContainerInterface */ |
||||
protected $container; |
||||
protected $tokenStorage; |
||||
|
||||
/** |
||||
* LegacyLoginListener constructor. |
||||
* |
||||
* @param ContainerInterface $container |
||||
* @param TokenStorageInterface $tokenStorage |
||||
*/ |
||||
public function __construct(ContainerInterface $container, TokenStorageInterface $tokenStorage) |
||||
{ |
||||
$this->container = $container; |
||||
$this->tokenStorage = $tokenStorage; |
||||
} |
||||
|
||||
/** |
||||
* @param GetResponseEvent $event |
||||
*/ |
||||
public function onKernelRequest(GetResponseEvent $event) |
||||
{ |
||||
$request = $event->getRequest(); |
||||
|
||||
if (!$request->hasPreviousSession()) { |
||||
return; |
||||
} |
||||
|
||||
$container = $this->container; |
||||
$token = $this->tokenStorage->getToken(); |
||||
if ($token) { |
||||
$isGranted = $container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY'); |
||||
if ($isGranted) { |
||||
} else { |
||||
if (isset($_SESSION) && isset($_SESSION['_user'])) { |
||||
if ($_SESSION['_user']['active'] == 1) { |
||||
$username = $_SESSION['_user']['username']; |
||||
$criteria = ['username' => $username]; |
||||
/** @var User $user */ |
||||
$user = $container->get('fos_user.user_manager')->findOneBy($criteria); |
||||
if ($user) { |
||||
$em = $container->get('doctrine'); |
||||
/** @var User $completeUser */ |
||||
$completeUser = $em->getRepository('ChamiloUserBundle:User')->findOneBy($criteria); |
||||
$user->setLanguage($completeUser->getLanguage()); |
||||
|
||||
$isAdminUser = $em->getRepository('ChamiloCoreBundle:Admin')->findOneBy(['userId' => $user->getId()]); |
||||
if ($isAdminUser) { |
||||
$user->setSuperAdmin(true); |
||||
} |
||||
|
||||
$languages = ['german' => 'de', 'english' => 'en', 'spanish' => 'es', 'french' => 'fr']; |
||||
$locale = isset($languages[$user->getLanguage()]) ? $languages[$user->getLanguage()] : ''; |
||||
if ($user && !empty($locale)) { |
||||
$user->setLocale($locale); |
||||
//$request->getSession()->set('_locale_user', $locale); |
||||
// if no explicit locale has been set on this request, use one from the session |
||||
$request->getSession()->set('_locale', $locale); |
||||
$request->setLocale($locale); |
||||
} |
||||
|
||||
$token = new UsernamePasswordToken($user, null, 'admin', $user->getRoles()); |
||||
$this->tokenStorage->setToken($token); //now the user is logged in |
||||
|
||||
//now dispatch the login event |
||||
$event = new InteractiveLoginEvent($request, $token); |
||||
$container->get('event_dispatcher')->dispatch("security.interactive_login", $event); |
||||
$container->get('event_dispatcher')->addListener( |
||||
KernelEvents::RESPONSE, |
||||
[$this, 'redirectUser'] |
||||
); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
public static function getSubscribedEvents() |
||||
{ |
||||
return [ |
||||
// must be registered before the default Locale listener |
||||
KernelEvents::REQUEST => [['onKernelRequest', 15]], |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param FilterResponseEvent $event |
||||
*/ |
||||
public function redirectUser(FilterResponseEvent $event) |
||||
{ |
||||
$uri = $event->getRequest()->getUri(); |
||||
// on effectue la redirection |
||||
$response = new RedirectResponse($uri); |
||||
$event->setResponse($response); |
||||
} |
||||
} |
@ -0,0 +1,43 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Repository; |
||||
|
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Doctrine\ORM\EntityRepository; |
||||
|
||||
/** |
||||
* Class MessageRepository. |
||||
* |
||||
* @package Chamilo\CoreBundle\Repository |
||||
*/ |
||||
class MessageRepository extends EntityRepository |
||||
{ |
||||
/** |
||||
* @param User $user |
||||
* @param int $lastMessageId |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function getFromLastOneReceived(User $user, $lastMessageId = 0) |
||||
{ |
||||
$qb = $this->createQueryBuilder('m'); |
||||
|
||||
$qb |
||||
->where( |
||||
$qb->expr()->eq('m.userReceiver', $user->getId()) |
||||
) |
||||
->andWhere( |
||||
$qb->expr()->eq('m.msgStatus', MESSAGE_STATUS_UNREAD) |
||||
) |
||||
->andWhere( |
||||
$qb->expr()->gt('m.id', (int) $lastMessageId) |
||||
) |
||||
->orderBy( |
||||
'm.sendDate', |
||||
'DESC' |
||||
); |
||||
|
||||
return $qb->getQuery()->getResult(); |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue