public function onPasswordChange(UserEvent $event) { $message = $this->mailer->createMessage()->setSubject(ojs . change_password)->setFrom($this->systemEmail)->setTo($event->getUser()->getEmail())->setBody($this->twig->render('OjsUserBundle:Mails:User/password_changed.html.twig', ['user' => $event->getUser()]))->setContentType('text/html'); $this->mailer->send($message); try { //log as eventlog $eventLog = new EventLog(); $eventLog->setEventInfo(UserEventLogParams::$PASSWORD_CHANGE); $eventLog->setIp($this->request->getCurrentRequest()->getClientIp()); $eventLog->setUserId($event->getUser()->getId()); $this->em->persist($eventLog); $this->em->flush(); } catch (\Exception $e) { } }
/** * Creates a Response object to send upon a successful logout. * * @param Request $request * * @return Response never null */ public function onLogoutSuccess(Request $request) { if ($this->tokenStorage->getToken()) { /* @var $user User */ $user = $this->tokenStorage->getToken()->getUser(); //log as eventlog $event = new EventLog(); $event->setEventInfo(UserEventLogParams::$USER_LOGOUT); $event->setIp($request->getClientIp()); $event->setUserId($user->getId()); $this->em->persist($event); $this->em->flush(); } $response = new RedirectResponse($this->router->generate('login')); return $response; }
/** * Every new user log to event log * @param LifecycleEventArgs|RequestStack $args * @link http://docs.doctrine-project.org/en/latest/reference/events.html#postupdate-postremove-postpersist * @return Response never null */ public function postPersist(LifecycleEventArgs $args) { if (php_sapi_name() != 'cli') { $entity = $args->getEntity(); $entityManager = $args->getEntityManager(); // perhaps you only want to act on some "User" entity if ($entity instanceof User) { //log as eventlog $event = new EventLog(); $event->setEventInfo(UserEventLogParams::$USER_ADD); $event->setIp($this->request->getCurrentRequest()->getClientIp()); $event->setUserId($entity->getId()); $entityManager->persist($event); $entityManager->flush(); } } }
/** * * @param InteractiveLoginEvent $event * @return void */ public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) { $request = $event->getRequest(); $token = $event->getAuthenticationToken(); if ($token && $token->getUser() instanceof User) { /* @var $user User */ // save last login $user = $token->getUser(); $user->setLastlogin(new \DateTime()); $this->em->persist($user); //log as eventlog $event = new EventLog(); $event->setEventInfo(UserEventLogParams::$USER_LOGIN); $event->setIp($request->getClientIp()); $event->setUserId($user->getId()); $this->em->persist($event); $this->em->flush(); } }
/** * Proxy drop event event log function. * @param LifecycleEventArgs $args * @return null */ public function preRemove(LifecycleEventArgs $args) { if (php_sapi_name() != 'cli') { $entity = $args->getEntity(); $entityManager = $args->getEntityManager(); /** * perhaps you only want to act on some "Proxy" entity * @link http://docs.doctrine-project.org/en/latest/reference/events.html#listening-and-subscribing-to-lifecycle-events */ if ($entity instanceof Proxy) { //log as eventlog $event = new EventLog(); $event->setEventInfo(ProxyEventLogParams::$PROXY_DROP); $event->setIp($this->request->getCurrentRequest()->getClientIp()); $event->setAffectedUserId($entity->getProxyUserId()); $event->setUserId($entity->getClientUserId()); $entityManager->persist($event); $entityManager->flush(); } } }
/** * Article remove event event log function. * @param LifecycleEventArgs $args * @return null */ public function preRemove(LifecycleEventArgs $args) { if (php_sapi_name() != 'cli') { $entity = $args->getEntity(); $entityManager = $args->getEntityManager(); /* @var $user User */ $user = $this->tokenStorage->getToken()->getUser(); /** * perhaps you only want to act on some "Article" entity * @link http://docs.doctrine-project.org/en/latest/reference/events.html#listening-and-subscribing-to-lifecycle-events */ if ($entity instanceof Article) { //log as eventlog $event = new EventLog(); $event->setEventInfo(ArticleEventLogParams::$ARTICLE_REMOVE); $event->setIp($this->request->getCurrentRequest()->getClientIp()); $event->setUserId($user->getId()); $event->setAffectedUserId($entity->getSubmitterId()); $entityManager->persist($event); $entityManager->flush(); } } }